Repository navigation
dylink: Synchronize dlsym (as well as dlopen) calls between threads - #18590
Merged
Merged
Conversation
sbc100
force-pushed
the
unify_symbol_table
branch
from
January 25, 2023 18:04
9d2f486 to
f7e4555
Compare
sbc100
force-pushed
the
dlsync_dlsym
branch
3 times, most recently
from
January 25, 2023 22:31
18b30a6 to
f93937f
Compare
kripken
reviewed
Jan 25, 2023
Prior to this change we were tracking the sequence of `dlopen` events and replaying them on each thread during `dlsync`. Now we also track `dlsym` events. A new data structure is used here to abstract over these two events (`dlevent`). During dlsync we then reply both the `dlopen` and the `dlsym` events. For `dlsym` events we serialized them as "dso+index", i.e. which dso did the symbol come from and what is the index of the symbol within that dso's symbol table. This is important for #18376.
kripken
approved these changes
Jan 26, 2023
This was referenced Nov 1, 2026
Closed
sbc100
pushed a commit
that referenced
this pull request
Nov 2, 2026
`_dlsym_js` enumerated every export of the library on each call, `Object.keys(lib.exports).indexOf(symbol)`, before doing anything else. For `RTLD_DEFAULT` on a main module that is `wasmImports`, which holds every export of the main module, so each `dlsym` call cost O(N log N) in the number of exported symbols (V8 sorts the keys of a dictionary-mode object on every `Object.keys`), whether the symbol exists or not. The index is only needed when `addFunction` allocates a new table slot and the other threads replay the insertion by index (`_dlsym_catchup_js`, #18590). This change tests membership with the `hasOwn` helper (`Object.hasOwn`) and gives the same answer as `Object.keys(...).indexOf(symbol) != -1` for these plain objects. It computes the enumeration index only in the branch that stores it into `symbolIndex`. The thread catch-up protocol is unchanged. Measured with a main module of N exported functions calling `dlsym(RTLD_DEFAULT, name)` (`emcc -O2 -pthread -sMAIN_MODULE=1 -sEXIT_RUNTIME=1`, Node 26.13.0, ms per call, hits): | exports | before | after | |---|---|---| | 10,000 | 1.70 | 0.008 | | 250,000 | 80.9 | 0.009 | Fixes #28124. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Fable 5.1 <[email protected]>
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.
Prior to this change we were tracking the sequence of
dlopeneventsand replaying them on each thread during
dlsync.Now we also track
dlsymevents. A new data structure is used here toabstract over these two events (
dlevent). During dlsync we then replyboth the
dlopenand thedlsymevents. Fordlsymevents weserialized them as "dso+index", i.e. which dso did the symbol come from
and what is the index of the symbol within that dso's symbol table.
This is important for #18376.