Skip to content

Revert "perf(standalone): madvise(MADV_DONTNEED) embedded source pages after entrypoint load" (#29320) - #37356

Closed
cirospaciari wants to merge 1 commit into
mainfrom
ciro/revert-29320
Closed

cirospaciari wants to merge 1 commit into
mainfrom
ciro/revert-29320

Conversation

@cirospaciari

Copy link
Copy Markdown
Member

What does this PR do?

Reverts #29320.

Removes the madvise(MADV_DONTNEED) hint that compiled standalone binaries issued over the embedded __BUN,__bun / .bun section after the entrypoint finished its initial evaluation:

  • Graph::hint_source_pages_dont_need() in src/standalone_graph/StandaloneModuleGraph.rs, along with the StandaloneModuleGraph debug log scope that standalone: route madvise hint logging through a scoped logger #34807 added solely for it
  • its call site in src/runtime/cli/run_command.rs
  • test/js/bun/compile/standalone-madvise-tla.test.ts and its test/expected-durations.json entry

The original change has since been ported from Zig to Rust, so this is a manual revert of the equivalent code rather than a git revert of c14e37e. The stderr assertions #34807 added to bundler_compile.test.ts / bun-build-compile.test.ts still hold (there is no longer anything to log), so they are left in place.

How did you verify your code works?

bun bd builds on macOS; nm/strings on the resulting binary no longer contain hint_source_pages_dont_need / hintSourcePagesDontNeed. A --compiled top-level-await entrypoint built with that binary runs to completion with exit 0 and empty stderr, including with BUN_DEBUG_StandaloneModuleGraph=1 set.

…s after entrypoint load" (#29320)

Removes the post-entrypoint MADV_DONTNEED hint over the embedded
__BUN/.bun section in compiled standalone binaries, together with the
StandaloneModuleGraph debug log scope that #34807 added for it, its call
site in run_command.rs, and the test that asserted the hint fired.

The original change has since been ported from Zig to Rust, so this
removes the equivalent Rust code rather than reverting c14e37e
directly.
@cirospaciari
cirospaciari marked this pull request as ready for review August 11, 2026 00:35
@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 333da0c1-469f-4cec-95ff-56a20650bb8d

📥 Commits

Reviewing files that changed from the base of the PR and between 23d233b and b32da33.

📒 Files selected for processing (4)
  • src/runtime/cli/run_command.rs
  • src/standalone_graph/StandaloneModuleGraph.rs
  • test/expected-durations.json
  • test/js/bun/compile/standalone-madvise-tla.test.ts
💤 Files with no reviewable changes (4)
  • test/expected-durations.json
  • test/js/bun/compile/standalone-madvise-tla.test.ts
  • src/standalone_graph/StandaloneModuleGraph.rs
  • src/runtime/cli/run_command.rs

Walkthrough

The standalone run path no longer performs source-page memory reclamation after entrypoint evaluation. The related graph API, scope registration, integration test, and expected-duration entries are removed.

Changes

Standalone graph hint removal

Layer / File(s) Summary
Remove source-page hinting path
src/runtime/cli/run_command.rs, src/standalone_graph/StandaloneModuleGraph.rs
The run command no longer calls Graph::hint_source_pages_dont_need(). The graph removes the scope registration and the platform-specific reclamation function.
Remove obsolete test coverage and timing data
test/js/bun/compile/standalone-madvise-tla.test.ts, test/expected-durations.json
The standalone top-level-await madvise integration test and its duration overrides are removed.
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the main change: reverting the standalone MADV_DONTNEED optimization.
Description check ✅ Passed The description explains the revert, lists affected changes, and documents build and runtime verification.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Comment @coderabbitai help to get the list of available commands.

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM — clean revert of the madvise(MADV_DONTNEED) hint and its supporting code.

What was reviewed:

  • Confirmed no remaining references to hint_source_pages_dont_need / hintSourcePagesDontNeed or scoped_log!(StandaloneModuleGraph, ...) anywhere in the tree, so removing declare_scope!(StandaloneModuleGraph) leaves nothing orphaned.
  • Checked that macho::get_data / elf::get_data are still used by from_executable(), so no dead helpers are left behind.
  • libc:: and bun_alloc:: were referenced fully-qualified inline (no top-level use), so no unused imports remain.
Extended reasoning...

Overview

This PR reverts #29320, which added a best-effort madvise(MADV_DONTNEED) over the embedded __BUN/.bun section of compiled standalone binaries after entrypoint evaluation. The revert is pure deletion across four files: the Graph::hint_source_pages_dont_need() function and its declare_scope! in StandaloneModuleGraph.rs, its single call site in run_command.rs, the dedicated test file standalone-madvise-tla.test.ts, and that test's expected-durations.json entry.

Security risks

None. This removes a kernel memory-advisory hint; the pre-#29320 behavior (no hint) is strictly the more conservative state.

Level of scrutiny

Low. This is a mechanical revert with no new logic — every hunk is a deletion. The only correctness question for a revert like this is whether it leaves anything dangling, and I verified it does not: no remaining callers of the removed function, no remaining users of the removed debug scope, no orphaned imports (the libc::madvise / bun_alloc::page_size calls were fully-qualified), and the platform section-data helpers (macho::get_data, elf::get_data) remain live via from_executable().

Other factors

The PR description explains this is a manual re-application of the revert against the post-Zig→Rust port, and that the stderr assertions from #34807 in bundler_compile.test.ts / bun-build-compile.test.ts remain valid (nothing to log now, so empty stderr still holds). The deleted test existed solely to prove the removed call site was reached, so deleting it alongside the code is the correct scope per the repo's "delete dead code in the same PR that makes it dead" rule.

Jarred-Sumner pushed a commit that referenced this pull request Aug 11, 2026
…ce (#37357)

### What does this PR do?

Adds `BUN_FEATURE_FLAG_DISABLE_STANDALONE_MADVISE`, a runtime opt-out
for the behavior introduced in #29320: a `bun build --compile`
executable calls `madvise(MADV_DONTNEED)` on its embedded source section
once the entrypoint has loaded, so anything that touches the source
afterwards (a lazy `require()`, resolving a stack trace) pages it back
in from the executable on disk. Deployments where that re-read is
undesirable can set the flag in the environment of the running
executable to keep the pages resident:

```sh
BUN_FEATURE_FLAG_DISABLE_STANDALONE_MADVISE=1 ./myapp
```

The compiled binary reads it at runtime, nothing is baked in at compile
time. It follows the existing `BUN_FEATURE_FLAG_DISABLE_*` escape
hatches: registered in `env_var.rs`, checked in
`hint_source_pages_dont_need()` (which returns early, sharing the
existing `len == 0` return), falsy values such as `0` keep the default.
No effect on Windows or on the plain interpreter, which never issue the
hint. Like the other `BUN_FEATURE_FLAG_DISABLE_*` escape hatches it is
not documented.

#37356 is the alternative of removing the madvise call altogether; the
two are mutually exclusive.

### How did you verify your code works?

`test/js/bun/compile/standalone-madvise-tla.test.ts` now runs the same
compiled binary three times with `BUN_DEBUG_StandaloneModuleGraph=1`:
with the variable unset (explicitly removed from the child env so an
ambient value on the host cannot leak in), set to `0`, and set to `1`.
The first two must log a `hintSourcePagesDontNeed:` line, the last must
not log one at all, since the flag path returns before logging anything.
The test stays debug-only because it relies on the scoped logger.

Against a debug build without this change the `1` case fails as
expected:

```
Expected to not contain: "hintSourcePagesDontNeed:"
Received: "before-await\nafter-await\n[standalonemodulegraph] hintSourcePagesDontNeed: MADV_DONTNEED 4096 bytes\n"
```

With the change, `bun bd test
test/js/bun/compile/standalone-madvise-tla.test.ts` passes (22
assertions).

<!-- robobun:evidence:begin -->

---

**no test proof** · iteration 1 · Platform-specific test(s) that do not
run on this machine. Deferring to CI, which covers all platforms:
test/js/bun/compile/standalone-madvise-tla.test.ts

<!-- robobun:evidence:end -->

---------

Co-authored-by: robobun <117481402+robobun@users.noreply.github.com>
@cirospaciari
cirospaciari deleted the ciro/revert-29320 branch September 4, 2026 23:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant