Skip to content

Commit 6add145

Browse files
authored
perf(runtime): compile large HTTP modules off the JS thread (#587)
ES modules fetched over HTTP by the async graph walk whose JavaScript body is 32 KiB or larger are now parsed and compiled to bytecode on a background thread through V8's streaming API; the JS thread only finalizes the result. Smaller bodies, JSON, failed fetches and the synchronous fallback compile as before. - A StreamedModuleCompile is started at fetch issue, parked in the isolate's ModuleLoaderState, fed the body once the transport completes, run on a dedicated pool, and finalized with ScriptCompiler::CompileModule(context, StreamedSource*, ...). Registration, request walking and error reporting are shared with the synchronous path through CompileAndRegisterModule. - Pure-ASCII bodies become external one-byte source strings, charged to the isolate as external memory. - The pool's threads have a 2 MB stack: V8's background parser checks for overflow against --stack-size (984 KB) below the point where Run() starts, which a 512 KB GCD thread cannot honour. - Non-debug runtimes pass kEagerCompile, since streaming ignores --no-lazy. - Bodies starting with a UTF-8 BOM are not streamed, because the stream drops the BOM while the source string keeps it. - Isolate teardown closes a gate, waits out running compiles while servicing nestable V8 tasks (where background GC requests land), and destroys unfinalized compiles before the isolate is disposed. Specs cover dynamic, static and pumped require() loads, non-ASCII sources, syntax errors, pathologically deep nesting, concurrent imports of one module and workers terminated mid-compile, against a generated module route added to the test server. The worker-teardown spec times one calibration import and terminates workers at evenly spaced fractions of that duration, so terminations land while a background compile is running whatever the machine's speed.
1 parent d888aad commit 6add145

5 files changed

Lines changed: 854 additions & 43 deletions

File tree

0 commit comments

Comments
 (0)