Skip to content

Find live toplevel bindings in Js_shake with a worklist - #8773

Merged
cknitt merged 3 commits into
perf-external-shadowfrom
perf-js-shake
Oct 10, 2026
Merged

cknitt merged 3 commits into
perf-external-shadowfrom
perf-js-shake

Conversation

@cknitt

@cknitt cknitt commented Oct 10, 2026

Copy link
Copy Markdown
Member

Stacked on #8772.

Js_shake decides which toplevel bindings of a module to keep. It repeated a full pass over all toplevel statements, recomputing the free variables of every initializer (the code had a TODO: add hashtbl for a cache), until no new binding became live. A dependency chain that runs backwards through the module needs one pass per link, which is quadratic.

The live set is the least set that contains the exports, the free variables of statements with side effects and the bindings whose initializer has side effects, and that contains the free variables of the initializer of every live binding. live_idents now computes the free variables of each initializer once and follows them with a worklist, which gives that same set in linear time.

Measurements

Same method as #8769, compared with the previous PR in the stack. All 574 files of tests/tests/src (not only the benchmark corpus) compile to byte-identical JS and diagnostics.

CPU time Allocated words
Stress: a chain of 1500 private functions where only the last one is exported, plus a dead chain of 300 549 → 290 ms (−47%) −54%
57 real files ≈ noise −0.08%

Modules whose live set settled in a single pass now pay a little for the dependency table (e.g. +1.9% allocation on a file with 1800 string literals), which is why real files come out about even.

🤖 Generated with Claude Code

@cknitt
cknitt added this pull request to stack #8775 October 10, 2026 10:17
@cknitt

cknitt commented Oct 10, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 10, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-10T10:49:34.890557Z 50b538b Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ffd5c80988

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread compiler/core/js_shake.ml
Comment thread CHANGELOG.md
@codecov

codecov Bot commented Oct 10, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.65217% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 80.66%. Comparing base (477b2fc) to head (36d26f2).

Files with missing lines Patch % Lines
compiler/core/js_shake.ml 95.65% 1 Missing ⚠️
Additional details and impacted files
@@                   Coverage Diff                    @@
##           perf-external-shadow    #8773      +/-   ##
========================================================
- Coverage                 80.66%   80.66%   -0.01%     
========================================================
  Files                       463      463              
  Lines                     62758    62755       -3     
========================================================
- Hits                      50623    50619       -4     
- Misses                    12135    12136       +1     
Files with missing lines Coverage Δ
compiler/core/js_shake.ml 86.11% <95.65%> (-3.64%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@cknitt

cknitt commented Oct 10, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🎉

Reviewed commit: 50b538bbf8

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@cknitt
cknitt marked this pull request as ready for review October 10, 2026 10:50
@cknitt
cknitt requested a review from cristianoc October 10, 2026 10:50
@pkg-pr-new

pkg-pr-new Bot commented Oct 10, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

rescript

npm i https://pkg.pr.new/rescript@8773

@rescript/belt

npm i https://pkg.pr.new/@rescript/belt@8773

@rescript/darwin-arm64

npm i https://pkg.pr.new/@rescript/darwin-arm64@8773

@rescript/darwin-x64

npm i https://pkg.pr.new/@rescript/darwin-x64@8773

@rescript/linux-arm64

npm i https://pkg.pr.new/@rescript/linux-arm64@8773

@rescript/linux-x64

npm i https://pkg.pr.new/@rescript/linux-x64@8773

@rescript/runtime

npm i https://pkg.pr.new/@rescript/runtime@8773

@rescript/win32-x64

npm i https://pkg.pr.new/@rescript/win32-x64@8773

commit: 36d26f2

cknitt and others added 3 commits October 10, 2026 15:22
Js_shake repeated a full pass over the module, recomputing every
initializer's free variables, until no new binding became live.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Christoph Knittel <ck@cca.io>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Christoph Knittel <ck@cca.io>
A backward chain to an export, helpers kept by statements with side
effects, and a dead chain that is removed (same JS as before the change).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Christoph Knittel <ck@cca.io>
@cknitt
cknitt merged commit 4f69e5d into master Oct 10, 2026
24 checks passed
@cknitt
cknitt deleted the perf-js-shake branch October 10, 2026 15:42
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.

2 participants