Skip to content

Mix the whole pointer when choosing a property lock - #415

Merged
davidchisnall merged 1 commit into
gnustep:masterfrom
DTW-Thalion:perf/spinlock-hash-whole-pointer
Aug 13, 2026
Merged

Mix the whole pointer when choosing a property lock#415
davidchisnall merged 1 commit into
gnustep:masterfrom
DTW-Thalion:perf/spinlock-hash-whole-pointer

Conversation

@DTW-Thalion

@DTW-Thalion DTW-Thalion commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

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.

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
DTW-Thalion marked this pull request as draft August 13, 2026 12:32
@DTW-Thalion
DTW-Thalion marked this pull request as ready for review August 13, 2026 12:33
@davidchisnall
davidchisnall merged commit 6f4b7ba into gnustep:master Aug 13, 2026
182 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants