-
-
Notifications
You must be signed in to change notification settings - Fork 14.8k
TLS lookups in libsyntax_pos are expensive #59718
Copy link
Copy link
Closed
Labels
A-thread-localsArea: Thread local storage (TLS)Area: Thread local storage (TLS)C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.I-compiletimeIssue: Problems and improvements with respect to compile times.Issue: Problems and improvements with respect to compile times.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Metadata
Metadata
Assignees
Labels
A-thread-localsArea: Thread local storage (TLS)Area: Thread local storage (TLS)C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.I-compiletimeIssue: Problems and improvements with respect to compile times.Issue: Problems and improvements with respect to compile times.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Type
Fields
Give feedbackNo fields configured for issues without a type.
#59693 is a nice speed-up for rustc, reducing instruction counts by as much as 12%. #59693 (comment) shows that approximately half the speedup is from avoiding TLS lookups.
So I thought: what else is using TLS lookups? I did some profiling and found that
syntax_pos::GLOBALSaccounts for most of it. It has three pieces,symbol_interner,hygiene_data,span_interner. I did some profiling of the places where they are accessed viaGLOBALS::with:These measurements are from a rustc that didn't have #59693's change applied, which avoids almost all of the
span_interneraccesses. And those accesses were only 11.0-24.8% of thesyntax_pos::GLOBALSaccesses. In other words, if we could eliminate most or all of thehygiene_dataandsymbol_interneraccesses, we'd get even bigger wins than what we saw in #59693.I admit that I don't understand how
syntax_pos::GLOBALSworks, why the TLS reference is needed for a global value.One possible idea is to increase the size of
Symbolfrom 4 bytes to 8 bytes, and then store short symbols (7 bytes or less) inline. Some preliminary profiling suggests this could capture roughly half of the symbols.hygiene_datais a harder nut to crack, being a more complicated structure.cc @rust-lang/wg-compiler-performance