What are Parse, Compile and Evaluate in DevTools Performance tool?

拟墨画扇 提交于 2020-12-02 07:18:04

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!