Repository navigation
Conversation
On Linux the fast thread-local slot, the GC's stack context, was read with pthread_getspecific: a call through the PLT on each allocation that leaves the inline path, each time a String or a number is boxed, and wherever HX_CTX_GET is used. In an OpenFL game it was 3 to 4% of the main thread's samples. With GCC and Clang on Linux it is now a __thread pointer, read with one load from the thread pointer. __thread rather than thread_local: for an extern thread_local, C++ calls a wrapper in case another unit initializes it dynamically. Defining HXCPP_PTHREAD_FAST_TLS keeps pthread_getspecific. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
On Linux, the fast thread-local slot (
DECLARE_FAST_TLS_DATA, used for theGC's stack context
tlsStackContext) is read withpthread_getspecific: acall through the PLT on each allocation that leaves the inline path, each time
a String or a number is boxed, and wherever
HX_CTX_GETis used. In theprofile of an OpenFL game,
pthread_getspecifictook 3 to 4% of the mainthread's samples, spread over allocations everywhere.
With GCC and Clang on Linux, the fast slot is now a
__threadpointer, readwith one load from the thread pointer.
__threadrather thanthread_local:for an
extern thread_local, C++ calls a wrapper in case another unitinitializes the variable dynamically. Only the fast slot changes, and only on
Linux, the platform this was measured on; defining
HXCPP_PTHREAD_FAST_TLSkeeps
pthread_getspecific. WinRT already declares the slot the same way.Benchmarks (
bash bench/ci.sh fb7f8045, Linux, Ryzen 7 3700X, gcc 14.2,3 processes x 5 samples): 20 improvements past the noise, among them
alloc_strings 1.14x, anon_field 1.22x, array_pop 1.16x, sort_int 1.12x and
1.07 to 1.16x on most CPPIA workloads. The two regressions it flagged
(cffi_string_view 0.86x, the tail pause of large_cache_purge) were level on a
rerun of those two with 5 processes x 10 samples (0.94x ±12%, 0.88x ±78%).
Tests: test/haxe, test/native and test/gc_stress (10 s with 4 threads, 60 s
with 8) pass on Linux 64-bit.