Skip to content

ExprAttrs::eval: Don't write to the shared empty Bindings#537

Merged
edolstra merged 1 commit into
mainfrom
empty-bindings
Jul 6, 2026
Merged

ExprAttrs::eval: Don't write to the shared empty Bindings#537
edolstra merged 1 commit into
mainfrom
empty-bindings

Conversation

@edolstra

@edolstra edolstra commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator

Motivation

This is a (probably harmless) data race, but more importantly, it causes a lot of false sharing on the cache line holding emptyBindings, which is bad for parallel eval.

Taken from #534.

Context

Evaluating an empty attrset literal wrote its position into
Bindings::emptyBindings, the shared static object that
EvalMemory::allocBindings() returns for zero-capacity bindings. Under
parallel evaluation this is a data race (the position of every '{ }'
was whichever one was evaluated last), and 'perf c2c' on an Intel
i7-1260P showed it also causes false sharing: emptyBindings happens
to share a cache line with Counter::enabled, which is read by every
thread in allocValue()/callFunction()/maybeThunk(), so each write
invalidated that line across all cores.

Skip the write for the shared empty bindings; '{ }' now has a
deterministic (undefined) position instead of a racy one, and the
cache line stays clean. Verified with perf c2c that the line no
longer appears among contended cache lines.

Assisted-by: Claude Fable 5 <noreply@anthropic.com>
@edolstra edolstra enabled auto-merge July 6, 2026 17:51
@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown

@github-actions github-actions Bot temporarily deployed to pull request July 6, 2026 17:56 Inactive
@edolstra edolstra added this pull request to the merge queue Jul 6, 2026
Merged via the queue into main with commit 46e041f Jul 6, 2026
32 checks passed
@edolstra edolstra deleted the empty-bindings branch July 6, 2026 18:32
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