Skip to content

Calculate transitive JS library deps after symbolHandler in --symbols-only mode. NFC - #28052

Merged
sbc100 merged 1 commit into
emscripten-core:mainfrom
sbc100:symbols-only-simplify
Oct 23, 2026
Merged

sbc100 merged 1 commit into
emscripten-core:mainfrom
sbc100:symbols-only-simplify

Conversation

@sbc100

@sbc100 sbc100 commented Oct 22, 2026

Copy link
Copy Markdown
Collaborator

Previously, getTransitiveDeps was called inside addFromLibrary while symbolHandler was still iterating through symbolsNeeded and mutating __deps (such as adding setTempRet0 for i64-returning functions without WASM_BIGINT).

Compute symbolDeps in the if (symbolsOnly) block after symbolHandler completes so that all direct __deps are populated before traversing the dependency graph.

Split out from #27995.

…ols-only` mode. NFC

Previously, `getTransitiveDeps` was called inside `addFromLibrary` while
`symbolHandler` was still iterating through `symbolsNeeded` and mutating
`__deps` (such as adding `setTempRet0` for i64-returning functions
without `WASM_BIGINT`).

Compute `symbolDeps` in the `if (symbolsOnly)` block after
`symbolHandler` completes so that all direct `__deps` are populated
before traversing the dependency graph.

Split out from emscripten-core#27995.
@sbc100
sbc100 requested a review from kripken October 22, 2026 21:39

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request refactors the --symbols-only mode in src/jsifier.mjs by moving the dependency resolution logic for library symbols to the end of the runJSify function, where it iterates over all keys of LibraryManager.library. However, calling the unmemoized getTransitiveDeps function on every library symbol introduces a performance bottleneck due to quadratic traversal of the dependency graph. It is recommended to implement a memoized version of dependency resolution to optimize compilation performance.

Comment thread src/jsifier.mjs
sbc100 added a commit to sbc100/emscripten that referenced this pull request Oct 22, 2026
Cache the computed transitive dependency list for each symbol in
`transitiveDepsCache` and reuse cached results when traversing
dependencies in subsequent `getTransitiveDeps` calls. Only completed
top-level traversals are inserted into the cache so that cyclic
dependencies (such as `$FS` <-> `$MEMFS`) are handled safely without
caching partial results.

In `tools/compiler.mjs --symbols-only`, this reduces graph node visits
in `getTransitiveDeps` by ~9x (from 39,349 to 4,381), cutting the
`symbolDeps` calculation time by ~41% (from ~16.0ms to ~9.5ms) and
overall `--symbols-only` execution time by ~4.6% (from ~152ms to
~145ms).

See: emscripten-core#28052
@sbc100
sbc100 requested a review from dschuff October 22, 2026 23:52
@sbc100
sbc100 enabled auto-merge (squash) October 23, 2026 00:10
sbc100 added a commit to sbc100/emscripten that referenced this pull request Oct 23, 2026
Cache the computed transitive dependency list for each symbol in
`transitiveDepsCache` and reuse cached results when traversing
dependencies in subsequent `getTransitiveDeps` calls. Only completed
top-level traversals are inserted into the cache so that cyclic
dependencies (such as `$FS` <-> `$MEMFS`) are handled safely without
caching partial results.

In `tools/compiler.mjs --symbols-only`, this reduces graph node visits
in `getTransitiveDeps` by ~9x (from 39,349 to 4,381), cutting the
`symbolDeps` calculation time by ~41% (from ~16.0ms to ~9.5ms) and
overall `--symbols-only` execution time by ~4.6% (from ~152ms to
~145ms).

See: emscripten-core#28052
@sbc100
sbc100 merged commit 6583f78 into emscripten-core:main Oct 23, 2026
42 checks passed
@sbc100
sbc100 deleted the symbols-only-simplify branch October 23, 2026 20:11
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