perf: small native tls optimisation#2512
Merged
Merged
Conversation
alexandre-daubois
approved these changes
Jul 8, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves runtime performance by forcing a more efficient TLS (thread-local storage) access pattern in the native C code and conditionally enabling -mtls-size=12 when the toolchain supports it, to help compilers/linkers emit shorter TLS sequences (notably on AArch64).
Changes:
- Add a small toolchain probe (
mtls-cflags.sh) that prints-mtls-size=12when compilation+linking succeeds with local-exec TLS. - Apply the detected TLS CFLAGS in both developer builds (
go.sh) and static builds (build-static.sh). - Force local-exec TLS for key TLS variables in
frankenphp.c, and update the performance docs wording aroundnum_threads.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| mtls-cflags.sh | New probe script to conditionally output -mtls-size=12 based on toolchain support. |
| go.sh | Appends the probe’s output to CGO_CFLAGS for regular Go builds. |
| frankenphp.c | Introduces THREAD_LOCAL with tls_model("local-exec") on ELF/GNU toolchains and applies it to TLS variables. |
| docs/performance.md | Updates guidance to configure num_threads via the global frankenphp directive. |
| build-static.sh | Exports CGO_CFLAGS with the probe result for static build workflows. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
dunglas
approved these changes
Jul 8, 2026
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.
This folds a 3 instruction tls load on aarch64 to a single mrs.
On x86-64 gnu ld should have relaxed it to a single fs anyway, but this guarantees it.