Skip to content

Mark thread-local variables as initial-exec#476

Merged
edolstra merged 1 commit into
mainfrom
initial-exec-tls
Jun 1, 2026
Merged

Mark thread-local variables as initial-exec#476
edolstra merged 1 commit into
mainfrom
initial-exec-tls

Conversation

@edolstra

@edolstra edolstra commented Jun 1, 2026

Copy link
Copy Markdown
Collaborator

Motivation

As suggested by @xokdvium, use the initial-exec model for thread-local storage. This should be faster, at least until NixOS/nixpkgs#518519 lands. It didn't show a clear performance improvement in my testing, e.g. on a nix search nixpkgs:

maximum RSS:        median = 5037324.0000  mean = 5040103.2000  stddev =  19835.2237  min = 5005472.0000  max = 5080404.0000  [not rejected, p=0.10552, Δ=-6886.93333±12125.09181]
soft page faults:   median = 1264925.0000  mean = 1265636.1333  stddev =   5001.5549  min = 1258135.0000  max = 1275674.0000  [not rejected, p=0.10466, Δ=-1707.91111±2999.43676]
system CPU time:    median =     40.9134  mean =     40.8374  stddev =      0.6536  min =     39.3454  max =     41.9917  [not rejected, p=0.49896, Δ=-0.09703±0.41150]
user CPU time:      median =     40.0625  mean =     39.7700  stddev =      0.8387  min =     38.0676  max =     40.8150  [rejected, p=0.00000, Δ=-1.03734±0.54708]
elapsed time:       median =     13.2556  mean =     12.7748  stddev =      0.7929  min =     11.4628  max =     13.5534  [not rejected, p=0.83082, Δ=-0.03600±0.48379]

however it shouldn't hurt either.

Context

Summary by CodeRabbit

  • Performance
    • Adjusted thread-local storage model across evaluation, parallel execution, logging, and signal handling to improve multi-threaded evaluation and responsiveness with no change to user-facing behavior.

@coderabbitai

coderabbitai Bot commented Jun 1, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 6e7c73f4-7c01-4b1b-b8c6-d0231325daf1

📥 Commits

Reviewing files that changed from the base of the PR and between 4c15336 and 3a91635.

📒 Files selected for processing (8)
  • src/libexpr/eval.cc
  • src/libexpr/include/nix/expr/eval-inline.hh
  • src/libexpr/include/nix/expr/eval.hh
  • src/libexpr/include/nix/expr/parallel-eval.hh
  • src/libexpr/parallel-eval.cc
  • src/libutil/logging.cc
  • src/libutil/unix/include/nix/util/signals-impl.hh
  • src/libutil/unix/signals.cc
✅ Files skipped from review due to trivial changes (3)
  • src/libexpr/include/nix/expr/parallel-eval.hh
  • src/libutil/logging.cc
  • src/libutil/unix/include/nix/util/signals-impl.hh
🚧 Files skipped from review as they are similar to previous changes (4)
  • src/libexpr/include/nix/expr/eval-inline.hh
  • src/libexpr/eval.cc
  • src/libexpr/include/nix/expr/eval.hh
  • src/libexpr/parallel-eval.cc

📝 Walkthrough

Walkthrough

This PR annotates fourteen existing thread_local variables across evaluator, allocator caches, parallel executor, logging, and signal handling with [[gnu::tls_model("initial-exec")]]. No runtime logic or control flow is changed.

Changes

Thread-Local Storage Model Optimization

Layer / File(s) Summary
EvalState thread-local annotations
src/libexpr/include/nix/expr/eval.hh, src/libexpr/eval.cc
EvalState::callDepth and EvalState::evalContext declarations and definitions gain [[gnu::tls_model("initial-exec")]].
Memory allocation cache thread-locals
src/libexpr/include/nix/expr/eval-inline.hh
GC allocation caches (valueAllocCache, env1AllocCache) and extern thread_local uint32_t myEvalThreadId are annotated with [[gnu::tls_model("initial-exec")]].
Executor parallel evaluation thread-locals
src/libexpr/include/nix/expr/parallel-eval.hh, src/libexpr/parallel-eval.cc
Executor::amWorkerThread, spawn-local std::random_device/std::uniform_int_distribution, and myEvalThreadId receive the initial-exec TLS model attribute.
Utility subsystem thread-locals
src/libutil/logging.cc, src/libutil/unix/include/nix/util/signals-impl.hh, src/libutil/unix/signals.cc
curActivity and interruptCheck declarations/definitions are annotated with [[gnu::tls_model("initial-exec")]].

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 I tuck each thread-local in its nest,

"initial-exec" gives them speed, not rest,
No logic hopped, no pathways rewired,
Just snappier hops where values are squired.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: adding the initial-exec TLS model attribute to thread-local variables across multiple files.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch initial-exec-tls

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions

github-actions Bot commented Jun 1, 2026

Copy link
Copy Markdown

@github-actions github-actions Bot temporarily deployed to pull request June 1, 2026 13:16 Inactive
@edolstra edolstra force-pushed the initial-exec-tls branch from 4c15336 to 3a91635 Compare June 1, 2026 15:45
@github-actions github-actions Bot temporarily deployed to pull request June 1, 2026 15:51 Inactive
@edolstra edolstra added this pull request to the merge queue Jun 1, 2026
Merged via the queue into main with commit 64ed6c3 Jun 1, 2026
29 checks passed
@edolstra edolstra deleted the initial-exec-tls branch June 1, 2026 17:07
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.

2 participants