Repository navigation
Calculate transitive JS library deps after symbolHandler in --symbols-only mode. NFC - #28052
Merged
Merged
Conversation
…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.
There was a problem hiding this comment.
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.
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
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
kripken
approved these changes
Oct 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Previously,
getTransitiveDepswas called insideaddFromLibrarywhilesymbolHandlerwas still iterating throughsymbolsNeededand mutating__deps(such as addingsetTempRet0for i64-returning functions withoutWASM_BIGINT).Compute
symbolDepsin theif (symbolsOnly)block aftersymbolHandlercompletes so that all direct__depsare populated before traversing the dependency graph.Split out from #27995.