问题
When running JS scripts in Chromes' Performance tab, I see there are three steps for JS interpretation: Parse
, Compile
and Evaluate
.
Sometimes I just see Evaluate
, sometimes Compile
and Evaluate
and sometimes it's the whole three.
My questions are:
- What each step actually means?
- Why sometimes there are missing steps? (for instance, sometimes
Parse
is missing)
回答1:
Parse:
The js engine goes over the code, determines all the different scopes, variable declarations etc. and sorts them. At this step also hoisting happens. Basically your plain text sourcecode is turned into an Abstract Syntax Tree (AST)
Compile:
Chromes V8 uses JIT compiling, that means that some parts of the js code are transfered into bytecode (that runs directly on your processor without any layer of abstraction inbetween). This increases performance. Sometimes it may decide to run the code directly without compiling it, e.g. if compiling it takes longer than actually running it unoptimized so there would be no benefit whatsoever.
Evaluating:
The code is run.
Read on:
How V8 optimizes
Bytecode vs. Running directly
All together
来源:https://stackoverflow.com/questions/48850493/what-are-parse-compile-and-evaluate-in-devtools-performance-tool