graphics: cache the macOS thread id in TrackingSpinLock #1169
No reviewers
Labels
No labels
bug
documentation
duplicate
enhancement
GPU
GUI
help wanted
question
Shaders
Video
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/KytyPS5--KytyPS5!1169
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1169/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@romainhedouin on GitHub · 2026-10-07 22:37 UTC · original
romainhedouin:perf/tracking-spinlock-thread-id→main· +3 −1 · 1 files · 1 commits · merged 2026-10-07 23:18 UTCFixes #1171.
On macOS, TrackingSpinLock asks the OS for the thread id (pthread_mach_thread_np) on every lock() and unlock()
The Linux path already caches it in a thread_local, so this does the same
An uncontended lock and unlock goes from 8.64 ns to 2.88 ns on an M4 Macbook
I tested it with a standalone program against the real header, before and after: 8 threads hammering one lock (20 rounds of fresh threads) with no lost updates, and the recursive lock and non owner unlock checks still abort the same way. I could not run MemoryTrackerTests itself because it does not build on arm64 macOS. Not run on x86_64
Here are the gains I measured on macOS when the render thread is the bottleneck:
I created a unit test but it seemed superfluous, let me know if I should add it to the PR
AI tools were used for code review and for drafting the checks I ran. I reviewed the diff and ran them
@coderabbitai[bot] on GitHub · 2026-10-07 22:59 UTC · original · edited 2026-10-07 23:00 UTC
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
9dfe25c9-214e-4006-8f6a-d21b29f40484📥 Commits
Reviewing files that changed from the base of the PR and between
420bb51d6candadf2464b15.📒 Files selected for processing (1)
src/graphics/host_gpu/regionManager.hIncluded review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.
📝 Walkthrough
Walkthrough
On Apple platforms,
TrackingSpinLock::CurrentThread()now caches the Mach thread ID in a thread-local constant. Later calls return that cached ID instead of querying and converting the thread port each time.Suggested reviewers:
nmzikPriority: ⬇️ Low
Change: Refactor · Severity of issue fixed: Low
Merge Risk: ⚪ Minimal · up to
adf24No actionable merge-blocking risk is established; this change caches the existing per-thread identifier used by the lock’s ownership checks.
🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
#1171requires per-thread caching of the macOS thread ID and preservation of recursive-lock and non-owner unlock checks. The diff changesTrackingSpinLock::CurrentThread()in `src/graphics/hos…src/graphics/host_gpu/regionManager.h. The change directly implements issue#1171and does not add unrelated production behavior or files.Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share
Comment
@coderabbitai helpto get the list of available commands.