Skip to content

Optimize Sorbet invocations#2565

Merged
amomchilov merged 4 commits intomainfrom
Alex/optimize-sorbet-calls
Mar 31, 2026
Merged

Optimize Sorbet invocations#2565
amomchilov merged 4 commits intomainfrom
Alex/optimize-sorbet-calls

Conversation

@amomchilov
Copy link
Copy Markdown
Contributor

Motivation

These invocations wasted a lot of time doing a full Sorbet type-check, grabbing the printed output they cared about but ignoring the tc results.

Implementation

Use --stop-after to terminate the Sorbet run after we've gotten what we needed.

Tests

None.

@amomchilov amomchilov requested a review from a team as a code owner March 31, 2026 21:19
sorbet("--print=missing-constants", "--quiet", "--stdout-hup-hack", "--no-error-count")
sorbet(
"--print=missing-constants",
"--stop-after=resolver",
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This shaves ~7.1 seconds off tapioca todo in Shopify's core monolith.

$ hyperfine --warmup 5 --runs 30 \ache-dir --print=missing-constants --quiet --stdout-hup-hack --no-error-count .'
  '~/sorbet-master --no-config --cache-dir --print=missing-constants --quiet --stdout-hup-hack --no-error-count --stop-after=resolver .' \
  '~/sorbet-master --no-config --cache-dir --print=missing-constants --quiet --stdout-hup-hack --no-error-count .'

Benchmark 1: ~/sorbet-master --no-config --cache-dir --print=missing-constants --quiet --stdout-hup-hack --no-error-count --stop-after=resolver .
  Time (mean ± σ):      7.445 s ±  0.223 s    [User: 16.044 s, System: 24.579 s]
  Range (min … max):    7.010 s …  7.955 s    30 runs
Benchmark 2: ~/sorbet-master --no-config --cache-dir --print=missing-constants --quiet --stdout-hup-hack --no-error-count .
  Time (mean ± σ):     14.582 s ±  0.757 s    [User: 65.227 s, System: 19.900 s]
  Range (min … max):   13.032 s … 16.134 s    30 runs
Summary
  ~/sorbet-master --no-config --cache-dir --print=missing-constants --quiet --stdout-hup-hack --no-error-count --stop-after=resolver . ran
    1.96 ± 0.12 times faster than ~/sorbet-master --no-config --cache-dir --print=missing-constants --quiet --stdout-hup-hack --no-error-count .

"--print=missing-constants",
"--stop-after=resolver",
"--quiet",
"--stdout-hup-hack",
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

What is stdout-hup-hack? Do other calls need it?

Comment on lines +91 to +92
unless supported_values.include?(table_type)
raise NotImplementedError, <<~MSG
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Did not test this, because it's really just a note to future developers who try to use a new value here. They'll need to adjust the stop-after to ensure it reaches the part of the pipeline they care about.

"--no-config",
"--quiet",
"--print=#{table_type}",
"--stop-after=namer",
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This shaves 8.1 seconds off the various commands that use it (tapioca gem, tapioca dsl) in Shopify's core monolith.

$hyperfine --warmup 5 --runs 30 \
  '~/sorbet-master --no-config --cache-dir --print=symbol-table-json --quiet --stop-after=namer .' \
  '~/sorbet-master --no-config --cache-dir --print=symbol-table-json --quiet .'

Benchmark 1: ~/sorbet-master --no-config --cache-dir --print=symbol-table-json --quiet --stop-after=namer .
   Time (mean ± σ):      6.148 s ±  0.228 s    [User: 10.487 s, System: 25.256 s]
   Range (min … max):    5.778 s …  6.869 s    30 runs
Benchmark 2: ~/sorbet-master --no-config --cache-dir --print=symbol-table-json --quiet .
  Time (mean ± σ):     14.254 s ±  0.686 s    [User: 65.621 s, System: 21.045 s]
  Range (min … max):   13.169 s … 15.899 s    30 runs

Summary
  ~/sorbet-master --no-config --cache-dir --print=symbol-table-json --quiet --stop-after=namer . ran
    2.32 ± 0.14 times faster than ~/sorbet-master --no-config --cache-dir --print=symbol-table-json --quiet .

@amomchilov amomchilov added the enhancement New feature or request label Mar 31, 2026
Copy link
Copy Markdown
Member

@paracycle paracycle left a comment

Choose a reason for hiding this comment

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

Thanks!

@amomchilov amomchilov enabled auto-merge March 31, 2026 21:33
@amomchilov amomchilov merged commit 041ad58 into main Mar 31, 2026
19 of 20 checks passed
@amomchilov amomchilov deleted the Alex/optimize-sorbet-calls branch March 31, 2026 21:44
raise NotImplementedError, <<~MSG
Got an unsupported value for `table_type` (#{table_type.inspect}).
The only supported values are:
#{supported_values.map { |v| "- #{v}" }.join("\n")}
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.

Nit: the \n from join won't have the heredoc indentation, so the second value will be unindented:

  - symbol-table-json
- symbol-table-full-json
Suggested change
#{supported_values.map { |v| "- #{v}" }.join("\n")}
#{supported_values.map { |v| "- #{v}" }.join("\n ")}

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