Skip to content

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

Closed
DTW-Thalion wants to merge 1 commit into
gnustep:masterfrom
DTW-Thalion:perf/spinlock-hash-whole-pointer
Closed

Mix the whole pointer when choosing a property lock#411
DTW-Thalion wants to merge 1 commit into
gnustep:masterfrom
DTW-Thalion:perf/spinlock-hash-whole-pointer

Conversation

@DTW-Thalion

Copy link
Copy Markdown
Contributor

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.

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.
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.

1 participant