Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move the constants in the precedence table into the header. #4308

Merged
merged 1 commit into from
Sep 13, 2024

Conversation

chandlerc
Copy link
Contributor

@chandlerc chandlerc commented Sep 12, 2024

Getting the basic constants is actually quite hot in the parser, and is
spending all of its time in memory stalls due to touching the call stack
just to return a constant when these are out-of-line.

This alone is worth another 8% improvement in parsing, and 2% in syntax
checking:

name                                               old cpu/op   new cpu/op   delta
BM_CompileAPIFileDenseDecls<Phase::Lex>/256        37.7µs ± 1%  37.5µs ± 2%  -0.58%  (p=0.019 n=19+18)
BM_CompileAPIFileDenseDecls<Phase::Lex>/1024        181µs ± 1%   179µs ± 2%  -0.95%  (p=0.001 n=20+20)
BM_CompileAPIFileDenseDecls<Phase::Lex>/4096        743µs ± 1%   736µs ± 2%  -0.85%  (p=0.001 n=20+19)
BM_CompileAPIFileDenseDecls<Phase::Lex>/16384      3.30ms ± 1%  3.25ms ± 2%  -1.48%  (p=0.000 n=17+19)
BM_CompileAPIFileDenseDecls<Phase::Lex>/65536      14.2ms ± 1%  13.9ms ± 2%  -1.95%  (p=0.000 n=17+19)
BM_CompileAPIFileDenseDecls<Phase::Lex>/262144     64.7ms ± 2%  63.8ms ± 2%  -1.30%  (p=0.000 n=18+18)
BM_CompileAPIFileDenseDecls<Phase::Parse>/256      71.0µs ± 1%  65.2µs ± 2%  -8.20%  (p=0.000 n=19+20)
BM_CompileAPIFileDenseDecls<Phase::Parse>/1024      351µs ± 1%   320µs ± 1%  -9.02%  (p=0.000 n=19+20)
BM_CompileAPIFileDenseDecls<Phase::Parse>/4096     1.43ms ± 2%  1.31ms ± 2%  -8.41%  (p=0.000 n=19+20)
BM_CompileAPIFileDenseDecls<Phase::Parse>/16384    6.08ms ± 2%  5.57ms ± 1%  -8.49%  (p=0.000 n=19+19)
BM_CompileAPIFileDenseDecls<Phase::Parse>/65536    25.2ms ± 1%  23.2ms ± 1%  -8.08%  (p=0.000 n=19+19)
BM_CompileAPIFileDenseDecls<Phase::Parse>/262144    109ms ± 1%   101ms ± 1%  -6.93%  (p=0.000 n=19+19)
BM_CompileAPIFileDenseDecls<Phase::Check>/256       752µs ± 1%   744µs ± 1%  -1.07%  (p=0.000 n=19+20)
BM_CompileAPIFileDenseDecls<Phase::Check>/1024     1.62ms ± 1%  1.59ms ± 1%  -1.88%  (p=0.000 n=19+20)
BM_CompileAPIFileDenseDecls<Phase::Check>/4096     4.97ms ± 2%  4.85ms ± 1%  -2.43%  (p=0.000 n=20+20)
BM_CompileAPIFileDenseDecls<Phase::Check>/16384    19.0ms ± 2%  18.5ms ± 2%  -2.32%  (p=0.000 n=19+20)
BM_CompileAPIFileDenseDecls<Phase::Check>/65536    78.8ms ± 2%  76.9ms ± 2%  -2.50%  (p=0.000 n=20+20)
BM_CompileAPIFileDenseDecls<Phase::Check>/262144    334ms ± 1%   327ms ± 2%  -2.29%  (p=0.000 n=20+20)

Copy link
Contributor

@zygoloid zygoloid left a comment

Choose a reason for hiding this comment

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

Looks good. (This seems to be independent of #4307, so could presumably be landed first if you wanted.)

Setting the basic constants is actually quite hot in the parser, and is
spending all of its time in memory stalls due to touching the call stack
just to return a constant when these are out-of-line.

This alone is worth another 8% improvement in parsing, and 2% in syntax
checking:
```
name                                               old cpu/op   new cpu/op   delta
BM_CompileAPIFileDenseDecls<Phase::Lex>/256        37.7µs ± 1%  37.5µs ± 2%  -0.58%  (p=0.019 n=19+18)
BM_CompileAPIFileDenseDecls<Phase::Lex>/1024        181µs ± 1%   179µs ± 2%  -0.95%  (p=0.001 n=20+20)
BM_CompileAPIFileDenseDecls<Phase::Lex>/4096        743µs ± 1%   736µs ± 2%  -0.85%  (p=0.001 n=20+19)
BM_CompileAPIFileDenseDecls<Phase::Lex>/16384      3.30ms ± 1%  3.25ms ± 2%  -1.48%  (p=0.000 n=17+19)
BM_CompileAPIFileDenseDecls<Phase::Lex>/65536      14.2ms ± 1%  13.9ms ± 2%  -1.95%  (p=0.000 n=17+19)
BM_CompileAPIFileDenseDecls<Phase::Lex>/262144     64.7ms ± 2%  63.8ms ± 2%  -1.30%  (p=0.000 n=18+18)
BM_CompileAPIFileDenseDecls<Phase::Parse>/256      71.0µs ± 1%  65.2µs ± 2%  -8.20%  (p=0.000 n=19+20)
BM_CompileAPIFileDenseDecls<Phase::Parse>/1024      351µs ± 1%   320µs ± 1%  -9.02%  (p=0.000 n=19+20)
BM_CompileAPIFileDenseDecls<Phase::Parse>/4096     1.43ms ± 2%  1.31ms ± 2%  -8.41%  (p=0.000 n=19+20)
BM_CompileAPIFileDenseDecls<Phase::Parse>/16384    6.08ms ± 2%  5.57ms ± 1%  -8.49%  (p=0.000 n=19+19)
BM_CompileAPIFileDenseDecls<Phase::Parse>/65536    25.2ms ± 1%  23.2ms ± 1%  -8.08%  (p=0.000 n=19+19)
BM_CompileAPIFileDenseDecls<Phase::Parse>/262144    109ms ± 1%   101ms ± 1%  -6.93%  (p=0.000 n=19+19)
BM_CompileAPIFileDenseDecls<Phase::Check>/256       752µs ± 1%   744µs ± 1%  -1.07%  (p=0.000 n=19+20)
BM_CompileAPIFileDenseDecls<Phase::Check>/1024     1.62ms ± 1%  1.59ms ± 1%  -1.88%  (p=0.000 n=19+20)
BM_CompileAPIFileDenseDecls<Phase::Check>/4096     4.97ms ± 2%  4.85ms ± 1%  -2.43%  (p=0.000 n=20+20)
BM_CompileAPIFileDenseDecls<Phase::Check>/16384    19.0ms ± 2%  18.5ms ± 2%  -2.32%  (p=0.000 n=19+20)
BM_CompileAPIFileDenseDecls<Phase::Check>/65536    78.8ms ± 2%  76.9ms ± 2%  -2.50%  (p=0.000 n=20+20)
BM_CompileAPIFileDenseDecls<Phase::Check>/262144    334ms ± 1%   327ms ± 2%  -2.29%  (p=0.000 n=20+20)
```
@chandlerc chandlerc added this pull request to the merge queue Sep 13, 2024
Merged via the queue into carbon-language:trunk with commit 02c2632 Sep 13, 2024
8 checks passed
@chandlerc chandlerc deleted the parse-opt branch September 13, 2024 10:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants