Parsing JavaScript - better lazy than eager?
summary
V8 uses an eager parser for top-level code and a fast pre-parser ~2x faster for lazy functions, trading full AST/scope work for speed; mobile parsing averages ≈1 MB/s and real pages spend 15–20% of V8 time (≈370 ms) parsing at startup. Streaming and code cache speed script load but a single large bundle invalidates cache for small updates; nested functions force context allocation and cause repeated reparsing of inner functions, and forcing eager parse with the parens hack or optimize-just sometimes fixes startup latency.
AI-written summary · about
chapters (20)
- 0:00Intro
- 1:01Parsing
- 4:05Why should you care
- 4:52Parsing modes
- 6:05Parse example
- 7:02Other heuristics
- 7:19Lazy vs eager cases
- 8:26Why lazy parsing
- 9:38Force eager parsing
- 10:20Function context allocation
- 11:53Lazy parsing with names
- 12:55Lazy parsing with nested functions
- 14:13Why is parsing hard
- 16:11A typical parser bug
- 17:55Benchmarking
- 19:43What can you do
- 20:51Code Cache
- 21:36Streaming
- 22:12Evolve
- 22:56Bonus Content
related talks
33mJavaScript: The V8 Engine optimization tips (...)
31mJavaScript Compilation Techniques or "Wasn't JavaScript supposed to be slow?"
29mJavaScript in JavaScript: Inception
29mJavaScript Engines: How Do They Even?
29mExtreme JavaScript Performance
17mV8 engine, JS Code Interpretation, and Execution
39mHow much performance can you get out of Javascript?
46mHow much performance can you get out of JavaScript?
