Repository navigation
engine: run pnpm run dev with --no-flush-liftoff-code - #265
ruifigueira wants to merge 1 commit into
Conversation
workerd signals memory pressure for every new isolate, so V8 drops the engine's shared Liftoff code on each navigation and the next page isolate compiles it again. The old code is not freed, so a local dev engine grew by about 5 MiB of executable code per navigation: 50 navigations on one page reached a 675 MB footprint, against 265 MB with the flag. The recompile also slowed navigations: warm navigations took 127 ms without the flag and 72 to 76 ms with it. The Docker image and the WPT runner already pass the flag. The dev, dev:wpt and dev:memprof scripts now pass it too, and the README says to include it when you override MINIFLARE_WORKERD_V8_FLAGS. beep-boop-🤖 Signed-off-by: Rui Figueira <rfigueira@cloudflare.com>
BernardoPe
left a comment
There was a problem hiding this comment.
beep-boop-bernardo-agent-🤖
One non-blocking documentation note on the README memory figures. No blocking findings.
| pressure for each new isolate, and without the flag V8 drops the engine's | ||
| compiled wasm code each time. Each page isolate then compiles it again, and the | ||
| old code stays in memory. In one test, 50 navigations on one page used 675 MB | ||
| without the flag and 280 MB with it. |
There was a problem hiding this comment.
beep-boop-bernardo-agent-🤖
Non-blocking (P4 - Documentation): README memory figures disagree with the measurement
This paragraph reports 280 MB for the run with both flags. The measurement table in the pull request description reports 265 MB for the same 50 navigations. The 675 MB baseline also came from a run with --no-expose-gc, so it had neither flag, and the drop from 675 MB is not the work of --no-flush-liftoff-code alone.
A reader who enables only the new flag and measures the footprint will see less saving than the text suggests. The executable code row in the table, 651 MB to 16 MB, is the one that isolates this flag.
State the flags each run used, or quote the executable code row only:
In one test, 50 navigations on one page used 675 MB with neither flag and 265 MB with both.Checked against the diff and the pull request description. The flag itself was accepted by the pinned workerd when run.
|
beep-boop-bernardo-agent-🤖 One non-blocking documentation note is inline: the README memory figures disagree with the measurement in the description. Agent review: APPROVE sha=990ae05180122b77e683f9be8d45038e61c992fa |
Summary
pnpm run devnow starts workerd with--no-flush-liftoff-codeas well as--expose-gc. The Docker image and the WPT runner already use both flags.workerd signals memory pressure each time it creates an isolate. On that signal, V8 throws away the engine's shared Liftoff code (V8's baseline compiled wasm), and the next page isolate compiles it again. The old code isn't freed, so a dev engine grows by about 5 MiB of executable code per navigation. I found this while checking whether #165 still reproduces: it was most of the growth I measured, and it isn't the page-isolate retention that #165 reports.
Behavior and API impact
None for the engine. Local dev uses less memory and navigates faster. If you set
MINIFLARE_WORKERD_V8_FLAGSyourself, your value still replaces the default.Implementation
packages/engine/package.json: thedev,dev:wptanddev:memprofscripts defaultMINIFLARE_WORKERD_V8_FLAGSto--expose-gc --no-flush-liftoff-code.README.md: explains the new flag, and says to include both flags when you override the default or startwrangler devdirectly.Validation
I ran the engine with
pnpm run devon macOS arm64 (workerd 1.20261123.1) and navigated one tab to the same small page 50 or 60 times over one CDP connection.footprint) after 50 navigationsThe two memory rows came from separate runs. The "before" memory run used
--no-expose-gc, and the "after" run used the new default. The timing rows used--expose-gcwith and without the new flag.pnpm run check: 32 of 33 checks pass.//:cargo_lock_testfails on my machine because it can't runrustcthrough a local wrapper (cask-rustc, "No such file or directory"). This change doesn't touch Rust or Cargo files.pnpm run test:e2e: not run. The change only affects the dev scripts, and the e2e config sets its own flags.I did not check Linux.
Risks and follow-ups
per-isolate bootstrap compile cache failed its compatibility checkat startup. That happens with any non-default V8 flag, including--expose-gcalone onmain, so this change doesn't add it. It shows only at startup, not on each navigation.new Worker()) still stay in memory until the client disconnects. That needs its own fix.Checklist
Signed-off-byline (git commit -s); see CONTRIBUTING.md.beep-boop-🤖