Mix the whole pointer when choosing a property lock - #411
Closed
DTW-Thalion wants to merge 1 commit into
Closed
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.
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 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. 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. ctest passes 198 of 198.
Draft: the figures come from one machine, and the choice of mixing function is worth an opinion.