Skip to content

engine: run pnpm run dev with --no-flush-liftoff-code - #265

Open
ruifigueira wants to merge 1 commit into
mainfrom
rfigueira/dev-no-flush-liftoff
Open

ruifigueira wants to merge 1 commit into
mainfrom
rfigueira/dev-no-flush-liftoff

Conversation

@ruifigueira

Copy link
Copy Markdown
Collaborator

Summary

pnpm run dev now starts workerd with --no-flush-liftoff-code as 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_FLAGS yourself, your value still replaces the default.

Implementation

  • packages/engine/package.json: the dev, dev:wpt and dev:memprof scripts default MINIFLARE_WORKERD_V8_FLAGS to --expose-gc --no-flush-liftoff-code.
  • README.md: explains the new flag, and says to include both flags when you override the default or start wrangler dev directly.

Validation

I ran the engine with pnpm run dev on macOS arm64 (workerd 1.20261123.1) and navigated one tab to the same small page 50 or 60 times over one CDP connection.

Before After
Executable (JIT) code after 50 navigations 651 MB 16 MB
Process footprint (footprint) after 50 navigations 675 MB 265 MB
Mean time per navigation, after the first 5 (2 runs of 60) 127.0 ms, 127.7 ms 72.4 ms, 76.1 ms

The 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-gc with and without the new flag.

  • pnpm run check: 32 of 33 checks pass. //:cargo_lock_test fails on my machine because it can't run rustc through 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

  • workerd logs per-isolate bootstrap compile cache failed its compatibility check at startup. That happens with any non-default V8 flag, including --expose-gc alone on main, so this change doesn't add it. It shows only at startup, not on each navigation.
  • Retired page isolates stay alive until the CDP connection closes #165 follow-up: page isolates are now released before the connection closes. Dedicated workers (new Worker()) still stay in memory until the client disconnects. That needs its own fix.

Checklist

  • This pull request solves one problem; see CONTRIBUTING.md.
  • Every commit has a Signed-off-by line (git commit -s); see CONTRIBUTING.md.
  • Added or updated focused tests for behavior changes. (Doesn't apply: dev script flag only.)
  • Updated documentation and generated files, or confirmed they do not apply.

beep-boop-🤖

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>
@github-actions github-actions Bot added the vouch:trusted Author is vouched, a collaborator, or a bot. label Nov 28, 2026
@BernardoPe BernardoPe assigned BernardoPe and unassigned BernardoPe Nov 28, 2026
@BernardoPe BernardoPe assigned BernardoPe and unassigned BernardoPe Nov 28, 2026

@BernardoPe BernardoPe left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

beep-boop-bernardo-agent-🤖

One non-blocking documentation note on the README memory figures. No blocking findings.

Comment thread README.md
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.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@BernardoPe

Copy link
Copy Markdown
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Ready for human review An independent agent reviewed this exact commit and found nothing blocking vouch:trusted Author is vouched, a collaborator, or a bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants