Mix the whole pointer when choosing a property lock - #415
Merged
davidchisnall merged 1 commit intoAug 13, 2026
Merged
Conversation
lock_for_pointer shifted the low 8 bits of the pointer away before indexing the lock table, so two properties in one object, and objects the allocator placed next to each other, took the same lock of the 1024 available. With 64 byte allocation alignment 4 consecutive objects always collide. The comment above the function names both cases as the ones the hash exists to keep apart. Every bit of the pointer now reaches the index, through the murmur3 finalizer, and through its 32 bit counterpart where a pointer is 32 bits. The cost is 3 instructions and no measurable time: 104.1 against 107.1 instructions per atomic set, and 21.8 ns either way across 5 runs in a fresh process each. ns per atomic objc_setProperty, one value object per thread, on 32 cores. Distinct objects: 8 threads 216.2 to 31.7, 24 threads 2133.2 to 80.6. Different properties of one object: 8 threads 1870.0 to 217.9, 24 threads 13193.1 to 278.8. objc_setAssociatedObject at 24 threads goes 369.7 to 119.6, since the association path takes a lock from the same table. Contended figures vary by about 2 times between runs on this machine; the shapes do not. The suite passes, 198 of 198.
DTW-Thalion
marked this pull request as draft
August 13, 2026 12:32
DTW-Thalion
marked this pull request as ready for review
August 13, 2026 12:33
davidchisnall
approved these changes
Aug 13, 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.
lock_for_pointer shifted the pointer right by 8 before indexing the lock table, so two properties in one object, and objects the allocator placed next to each other, took the same lock of the 1024 available. The comment above the function names both cases as the ones it exists to keep apart.
Every bit of the pointer now reaches the index, through the murmur3 finalizer, and its 32 bit counterpart for 32 bit pointers.
Dropping only the bits an aligned pointer cannot use, by shifting 3 rather than 8, is not enough on its own, because the low bits are then or'ed into the high ones and how much that recovers depends on the address. Distinct indices for 16 properties, 8 bytes apart in one object: 1 of 16 before, 16 of 16 after, and shifting alone gives 8 of 16 at one heap base and 2 of 16 at another.
ns per atomic objc_setProperty on 32 cores at 24 threads, minimum of 3: different properties of one object 13123 to 285, distinct objects 1987 to 81. One thread is unchanged and the mix costs 3 instructions.
Suite passes, 198 of 198.