Skip to content

Add Pyodide dynlink patches to improve startup time - #8866

Merged
ryanking13 merged 1 commit into
mainfrom
gyeongjae/pyodide-dylink-startup-patches
Nov 25, 2026
Merged

ryanking13 merged 1 commit into
mainfrom
gyeongjae/pyodide-dylink-startup-patches

Conversation

@ryanking13

@ryanking13 ryanking13 commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Applies two emscripten patches that optimize the Python workers startup.

When tested locally the instantiate_emscripten span got improved 6-8 ms. The p50 of instantiate_emscripten span was 2x slower in prod environment compared to my local environment. I am expecting 12-15ms improvements in prod.

@ryanking13
ryanking13 requested review from a team as code owners November 24, 2026 07:14

@clanky-the-clanker clanky-the-clanker 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.

Superseded by the review of 3e3a1692.

This review, of 3713561a

✅ Approved — This is a self-contained startup optimization made through build-time source patches that check their own match counts, and the version and integrity references are consistent. No issues found.

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.


✅ All checks passed

🔒 Security: ✅ LGTM

No security concerns.


📖 AGENTS.md: ✅ LGTM

No AGENTS.md updates needed.


📋 Code Quality: ✅ LGTM

The new patches use the existing match-count safety net. The newWasmModule rewrite still counts correctly under post-order traversal. The bundle version and integrity hash are consistent across all build files.


⚡ Performance: ✅ LGTM

Caching the wrapper module per signature and visiting only the unresolved GOT entries both reduce startup work as intended.


📝 Documentation: ✅ LGTM

The comments describe the current behaviour and link to the upstream changes.


Reviewed commit: 3713561a

@ryanking13
ryanking13 force-pushed the gyeongjae/pyodide-dylink-startup-patches branch from 3713561 to 3e3a169 Compare November 25, 2026 05:34

@clanky-the-clanker clanky-the-clanker 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.

Superseded by the review of af0c15e1.

This review, of 3e3a1692

💬 Approved with comments — The refactor and the startup patches look correct; the only note is an INFO about the wording of the doc comment on the once-only initPython guard.

Findings: 1 info (1 is an inline comment on the diff)

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.


📝 Documentation: 💬 1 info

One doc comment describes what a second initPython() call would do, but the code now throws on that call.

Recommendation: 💬 Optional Nits

  • [INFO] initPython doc comment says a second call would replace state, but the function throws on a second call. (src/pyodide/python-entrypoint-helper.ts:714)
View full review
  • src/pyodide/python-entrypoint-helper.ts:714: The doc comment says a second call would replace the state set up by the first call. In fact, the guard below the comment throws on a second call.

✅ All other checks passed

🔒 Security: ✅ LGTM

No security concerns.


📖 AGENTS.md: ✅ LGTM

No AGENTS.md updates needed.


📋 Code Quality: ✅ LGTM

The entrypoint refactor keeps the existing behaviour, and no callers of the removed setDoAnImport API remain. The bundle version and integrity hash are the same in every build file.


⚡ Performance: ✅ LGTM

Caching the wrapper module per signature and visiting only the unresolved GOT entries both cut startup work, as intended.


Reviewed commit: 3e3a1692

Comment thread src/pyodide/python-entrypoint-helper.ts Resolved
@ryanking13 ryanking13 closed this Nov 25, 2026
@ryanking13
ryanking13 force-pushed the gyeongjae/pyodide-dylink-startup-patches branch from 3e3a169 to 25c2041 Compare November 25, 2026 05:48
@ryanking13 ryanking13 reopened this Nov 25, 2026

@clanky-the-clanker clanky-the-clanker 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.

✅ Approved — The startup patches and the bundle version bump are consistent and correct. The only note from the last review was about a file this pull request no longer changes.

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.


✅ All checks passed

🔒 Security: ✅ LGTM

The cache key comes from the loader's own wasm signatures, not from request input. Missing required symbols still throw, and weak symbols still resolve to 0. The bundle is fetched under a pinned sha256.


📖 AGENTS.md: ✅ LGTM

No AGENTS.md updates needed.


📋 Code Quality: ✅ LGTM

The visit traversal is post-order, so the common newWasmModule patch is applied before the new convertJsFunctionToWasm replacement. The common patch still expects 4 matches. Each new patch expects exactly one match. The backport bump from 12 to 13 and its integrity hash are the same in all three build files.


⚡ Performance: ✅ LGTM

wrapperModuleCache grows only with the number of distinct wasm signatures. unresolvedSymbols shrinks as entries are resolved, so visits stop once symbols are handled.


📝 Documentation: ✅ LGTM

No documentation issues.


Reviewed commit: af0c15e1

@ryanking13
ryanking13 merged commit 6731947 into main Nov 25, 2026
24 checks passed
@ryanking13
ryanking13 deleted the gyeongjae/pyodide-dylink-startup-patches branch November 25, 2026 06:50
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