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

perf: use phf for more efficient lookup tables #5264

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

anonrig
Copy link
Contributor

@anonrig anonrig commented Dec 27, 2023

Replaces function with a lookup table generated at compile time.

Before

Timer precision: 41 ns
processors    fastest       │ slowest       │ median        │ mean          │ samples │ iters
├─ functions                │               │               │               │         │
│  ├─ 1       26.1 ms       │ 47.4 ms       │ 28.17 ms      │ 31.87 ms      │ 100     │ 100
│  │          191.5 Kitem/s │ 105.4 Kitem/s │ 177.4 Kitem/s │ 156.8 Kitem/s │         │
│  ├─ 4       17.88 ms      │ 22.11 ms      │ 18.63 ms      │ 18.9 ms       │ 100     │ 100
│  │          279.5 Kitem/s │ 226.1 Kitem/s │ 268.2 Kitem/s │ 264.4 Kitem/s │         │
│  ╰─ 16      13.11 ms      │ 14.72 ms      │ 14.03 ms      │ 14.02 ms      │ 100     │ 100
│             381.1 Kitem/s │ 339.5 Kitem/s │ 356.2 Kitem/s │ 356.5 Kitem/s │         │
├─ profiles                 │               │               │               │         │
│  ├─ 1       21.13 ms      │ 30.97 ms      │ 22.06 ms      │ 22.42 ms      │ 100     │ 100
│  │          236.5 Kitem/s │ 161.4 Kitem/s │ 226.6 Kitem/s │ 222.9 Kitem/s │         │
│  ├─ 4       14.79 ms      │ 21.33 ms      │ 15.52 ms      │ 16.15 ms      │ 100     │ 100
│  │          337.8 Kitem/s │ 234.3 Kitem/s │ 322 Kitem/s   │ 309.5 Kitem/s │         │
│  ╰─ 16      12.07 ms      │ 14.06 ms      │ 13.18 ms      │ 13.14 ms      │ 100     │ 100
│             414 Kitem/s   │ 355.4 Kitem/s │ 379.2 Kitem/s │ 380.4 Kitem/s │         │
├─ querylog                 │               │               │               │         │
│  ├─ 1       66.27 ms      │ 79.11 ms      │ 69.65 ms      │ 70.07 ms      │ 100     │ 100
│  │          75.44 Kitem/s │ 63.19 Kitem/s │ 71.77 Kitem/s │ 71.34 Kitem/s │         │
│  ├─ 4       39.23 ms      │ 48.8 ms       │ 43.72 ms      │ 43.94 ms      │ 100     │ 100
│  │          127.4 Kitem/s │ 102.4 Kitem/s │ 114.3 Kitem/s │ 113.7 Kitem/s │         │
│  ╰─ 16      28.36 ms      │ 31.16 ms      │ 29.94 ms      │ 29.94 ms      │ 100     │ 100
│             176.2 Kitem/s │ 160.4 Kitem/s │ 166.9 Kitem/s │ 166.9 Kitem/s │         │
╰─ spans                    │               │               │               │         │
   ├─ 1       32.38 ms      │ 47.77 ms      │ 34.71 ms      │ 35.29 ms      │ 100     │ 100
   │          154.4 Kitem/s │ 104.6 Kitem/s │ 144 Kitem/s   │ 141.6 Kitem/s │         │
   ├─ 4       22.14 ms      │ 26.16 ms      │ 23.71 ms      │ 23.8 ms       │ 100     │ 100
   │          225.7 Kitem/s │ 191 Kitem/s   │ 210.8 Kitem/s │ 210 Kitem/s   │         │
   ╰─ 16      15.23 ms      │ 18.39 ms      │ 16.27 ms      │ 16.29 ms      │ 100     │ 100
              328 Kitem/s   │ 271.7 Kitem/s │ 307.2 Kitem/s │ 306.8 Kitem/s │         

After

Timer precision: 41 ns
processors    fastest       │ slowest       │ median        │ mean          │ samples │ iters
├─ functions                │               │               │               │         │
│  ├─ 1       25.99 ms      │ 45.83 ms      │ 27.21 ms      │ 28.95 ms      │ 100     │ 100
│  │          192.3 Kitem/s │ 109 Kitem/s   │ 183.7 Kitem/s │ 172.7 Kitem/s │         │
│  ├─ 4       17.62 ms      │ 22.63 ms      │ 19.69 ms      │ 20.03 ms      │ 100     │ 100
│  │          283.7 Kitem/s │ 220.8 Kitem/s │ 253.8 Kitem/s │ 249.6 Kitem/s │         │
│  ╰─ 16      13.23 ms      │ 17.97 ms      │ 14.11 ms      │ 14.21 ms      │ 100     │ 100
│             377.7 Kitem/s │ 278.1 Kitem/s │ 354.3 Kitem/s │ 351.7 Kitem/s │         │
├─ profiles                 │               │               │               │         │
│  ├─ 1       21.3 ms       │ 33.45 ms      │ 22.27 ms      │ 22.62 ms      │ 100     │ 100
│  │          234.6 Kitem/s │ 149.4 Kitem/s │ 224.4 Kitem/s │ 220.9 Kitem/s │         │
│  ├─ 4       14.86 ms      │ 19.7 ms       │ 16.16 ms      │ 16.33 ms      │ 100     │ 100
│  │          336.4 Kitem/s │ 253.7 Kitem/s │ 309.2 Kitem/s │ 306.1 Kitem/s │         │
│  ╰─ 16      12.04 ms      │ 14.5 ms       │ 13.12 ms      │ 13.13 ms      │ 100     │ 100
│             415.1 Kitem/s │ 344.6 Kitem/s │ 380.8 Kitem/s │ 380.5 Kitem/s │         │
├─ querylog                 │               │               │               │         │
│  ├─ 1       67.32 ms      │ 75.44 ms      │ 69.05 ms      │ 69.68 ms      │ 100     │ 100
│  │          74.26 Kitem/s │ 66.27 Kitem/s │ 72.4 Kitem/s  │ 71.75 Kitem/s │         │
│  ├─ 4       40.22 ms      │ 46.62 ms      │ 43.94 ms      │ 43.78 ms      │ 100     │ 100
│  │          124.3 Kitem/s │ 107.2 Kitem/s │ 113.7 Kitem/s │ 114.1 Kitem/s │         │
│  ╰─ 16      28.49 ms      │ 33.41 ms      │ 30.37 ms      │ 30.37 ms      │ 100     │ 100
│             175.4 Kitem/s │ 149.6 Kitem/s │ 164.5 Kitem/s │ 164.5 Kitem/s │         │
╰─ spans                    │               │               │               │         │
   ├─ 1       32.41 ms      │ 42.28 ms      │ 34.64 ms      │ 35.28 ms      │ 100     │ 100
   │          154.2 Kitem/s │ 118.2 Kitem/s │ 144.3 Kitem/s │ 141.6 Kitem/s │         │
   ├─ 4       23.53 ms      │ 28.37 ms      │ 25.72 ms      │ 25.91 ms      │ 100     │ 100
   │          212.4 Kitem/s │ 176.2 Kitem/s │ 194.3 Kitem/s │ 192.9 Kitem/s │         │
   ╰─ 16      15.68 ms      │ 17.93 ms      │ 16.59 ms      │ 16.62 ms      │ 100     │ 100
              318.8 Kitem/s │ 278.7 Kitem/s │ 301.2 Kitem/s │ 300.8 Kitem/s │         │

@anonrig anonrig requested a review from a team as a code owner December 27, 2023 16:33
Copy link

codecov bot commented Dec 27, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (8e458a7) 93.12% compared to head (48c0804) 90.73%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5264      +/-   ##
==========================================
- Coverage   93.12%   90.73%   -2.40%     
==========================================
  Files         838      879      +41     
  Lines       41423    43053    +1630     
  Branches        0      288     +288     
==========================================
+ Hits        38577    39065     +488     
- Misses       2846     3946    +1100     
- Partials        0       42      +42     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@untitaker
Copy link
Member

i wouldn't do this -- this is not a hot function and I am skeptical that for tables of this size, match is slower than phf. benchmark delta seems to be within error range.

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