Skip to content

Use Sorbet cache (if enabled)#2568

Open
amomchilov wants to merge 1 commit intoAlex/use-prism-in-sorbet-callsfrom
Alex/use-sorbet-cache
Open

Use Sorbet cache (if enabled)#2568
amomchilov wants to merge 1 commit intoAlex/use-prism-in-sorbet-callsfrom
Alex/use-sorbet-cache

Conversation

@amomchilov
Copy link
Copy Markdown
Contributor

@amomchilov amomchilov commented Apr 1, 2026

Motivation

If a repo has enabled the Sorbet cache, we should use it.

Implementation

Builds upon the SorbetCache #2568.

Performance

Shaves off around ~3s on the Shopify core monolith.

The cache stores the desugared ASTs, after the parsing, RBS rewriting, and desugaring is done. If there's a cache hit, no parsing happens, so that's why you see the legacy and Prism parsers have the same time. So this mitigates some of the benefit of #2567, but Prism is still helpful when there's a cache miss.

hyperfine --warmup 5 --runs 20 \
  -n "prism, with cache"  '~/sorbet-master --no-config --cache-dir=tmp/sorbet_cache --parser=prism    --print=symbol-table-json --quiet --stop-after=namer .' \
  -n "legacy, with cache" '~/sorbet-master --no-config --cache-dir=tmp/sorbet_cache --parser=original --print=symbol-table-json --quiet --stop-after=namer .' \
  -n "legacy, no cache"   '~/sorbet-master --no-config --cache-dir=                 --parser=original --print=symbol-table-json --quiet --stop-after=namer .' \

  -n "prism, no cache"    '~/sorbet-master --no-config --cache-dir=                 --parser=prism    --print=symbol-table-json --quiet --stop-after=namer .'

Benchmark 1: "prism, with cache"
  Time (mean ± σ):     24.932 s ±  0.687 s    [User: 23.678 s, System: 18.433 s]
  Range (min … max):   23.812 s … 26.870 s    20 runs
  
Benchmark 2: "legacy, with cache"
  Time (mean ± σ):     25.031 s ±  0.354 s    [User: 23.550 s, System: 18.331 s]
  Range (min … max):   24.518 s … 25.917 s    20 runs

Benchmark 3: "prism, no cache"
  Time (mean ± σ):     26.880 s ±  0.494 s    [User: 44.113 s, System: 18.467 s]
  Range (min … max):   25.809 s … 27.619 s    20 runs
  
Benchmark 4: "legacy, no cache"
  Time (mean ± σ):     28.100 s ±  0.795 s    [User: 64.862 s, System: 18.303 s]
  Range (min … max):   27.020 s … 29.405 s    20 runs


Summary
  "prism, with cache" ran
    1.00 ± 0.03 times faster than "legacy, with cache"
    1.08 ± 0.04 times faster than "prism, no cache"
    1.13 ± 0.04 times faster than "legacy, no cache"

Tests

Added.

@amomchilov
Copy link
Copy Markdown
Contributor Author

amomchilov commented Apr 1, 2026

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

@amomchilov amomchilov changed the title Use Sorbet cache, if enabled Use Sorbet cache Apr 1, 2026
@amomchilov amomchilov changed the title Use Sorbet cache Use Sorbet cache (if enabled) Apr 1, 2026
@amomchilov amomchilov force-pushed the Alex/use-prism-in-sorbet-calls branch from 502c337 to 9c3e29b Compare April 1, 2026 01:45
@amomchilov amomchilov force-pushed the Alex/use-sorbet-cache branch from 1610659 to 3e06485 Compare April 1, 2026 01:45
@amomchilov amomchilov added enhancement New feature or request sorbet labels Apr 1, 2026
@amomchilov amomchilov marked this pull request as ready for review April 1, 2026 01:47
@amomchilov amomchilov requested a review from a team as a code owner April 1, 2026 01:47
# `--cache-dir=` disables the cache, modeled here with a `nil` value
cache_dir: if (value = options["--cache-dir"]).is_a?(String)
value.empty? ? nil : value
end,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this would be more readable outside of new, was there a specific reason to have it here?

Also should this use shellescape?

Copy link
Copy Markdown
Contributor Author

@amomchilov amomchilov Apr 1, 2026

Choose a reason for hiding this comment

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

Sure, I extracted local variables

Also should this use shellescape?

I don't think so. The C++ code consumes these values directly, not mediated by a shell.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Sure, I extracted local variables

Did you?

Are we missing a push?

@amomchilov amomchilov force-pushed the Alex/use-prism-in-sorbet-calls branch from 9c3e29b to 0189305 Compare April 1, 2026 18:16
@amomchilov amomchilov force-pushed the Alex/use-sorbet-cache branch from 3e06485 to 57f7cb0 Compare April 1, 2026 18:16
@amomchilov amomchilov requested a review from KaanOzkan April 1, 2026 18:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request sorbet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants