Skip to content

perf: small native tls optimisation#2512

Merged
henderkes merged 5 commits into
mainfrom
perf/le-tls
Jul 8, 2026
Merged

perf: small native tls optimisation#2512
henderkes merged 5 commits into
mainfrom
perf/le-tls

Conversation

@henderkes

@henderkes henderkes commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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=12 when 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 around num_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.

Comment thread mtls-cflags.sh
Comment thread docs/performance.md
@henderkes henderkes merged commit a00bb02 into main Jul 8, 2026
95 of 97 checks passed
@henderkes henderkes deleted the perf/le-tls branch July 8, 2026 23:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants