Repository navigation
Read registered component indices lock-free - #189
Merged
Merged
Conversation
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.
Description
Types that conform to
Componentwithout the@Componentmacro resolvecomponentIndexthroughNexus.ComponentIndexRegistryon every typed access. Before this change, every such access took a global pthread mutex and did a SipHash dictionary probe. Found while analysing theentity.lookup.noneregression in the benchmark comparison (#187).Lookups of already registered types are now lock-free. Readers run in parallel and never block, and only the first registration of a type takes the lock.
Detailed Design
CFirebladeAtomics, which adds no new dependency. It provides twostatic inlinehelpers, an acquire load and a release store on a plainuintptr_tword, built on__atomic_load_nand__atomic_store_n. The package declares no minimum platform, soSynchronization.Atomicis not an option.ObjectIdentifierbits) is published through an atomic pointer.indexLimitprecondition,count, indices assigned by the macro, and the WASI no-op lock.Documentation
The design and memory bounds are in the symbol docs of
ComponentIndexRegistryinComponentIndex.swift.Testing
make testandmake build-releasepass.swift test --sanitize=thread --filter ComponentIndexreports no data races.Performance
Micro-benchmark, release build, best of 7, 20M calls, ns per call:
get, plainComponentget, plainComponentget,@ComponentSource Impact
None, apart from the new internal C module.
Checklist
make pre-commitand verified all checks pass.make testpasses.make linthas no findings in the changed code but fails on indentation errors that already exist onmain.https://claude.ai/code/session_01QVgj7qq418b9eVorviMYDS