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

Prism benchmarks #30

Merged
merged 3 commits into from
Jul 19, 2024
Merged

Conversation

egiurleo
Copy link

@egiurleo egiurleo commented Jul 16, 2024

Motivation

This PR introduces a script to run benchmarks comparing the performance of the Prism parser to the Sorbet parser. The results will be saved in JSON files, allowing us to compare the performance of the Prism and Sorbet parser at any given time, as well as over time.

Benchmark Results

Benchmark 1: yjit-bench, parser only

Benchmark 1: bazel-bin/main/sorbet --parser=sorbet --stop-after=parser ../yjit-bench/benchmarks
  Time (mean ± σ):     13.984 s ±  0.375 s    [User: 22.977 s, System: 0.735 s]
  Range (min … max):   13.452 s … 14.834 s    10 runs

Benchmark 2: bazel-bin/main/sorbet --parser=prism --stop-after=parser ../yjit-bench/benchmarks
  Time (mean ± σ):      8.630 s ±  0.102 s    [User: 11.003 s, System: 0.938 s]
  Range (min … max):    8.504 s …  8.856 s    10 runs

Summary
  bazel-bin/main/sorbet --parser=prism --stop-after=parser ../yjit-bench/benchmarks ran
    1.62 ± 0.05 times faster than bazel-bin/main/sorbet --parser=sorbet --stop-after=parser ../yjit-bench/benchmarks

Benchmark 2: sorbet-test, parser only

Benchmark 1: bazel-bin/main/sorbet --parser=sorbet --stop-after=parser test/testdata
  Time (mean ± σ):     10.043 s ±  0.025 s    [User: 15.975 s, System: 1.059 s]
  Range (min … max):   10.008 s … 10.082 s    10 runs

  Warning: Ignoring non-zero exit code.

Benchmark 2: bazel-bin/main/sorbet --parser=prism --stop-after=parser test/testdata
  Time (mean ± σ):      9.029 s ±  0.117 s    [User: 12.662 s, System: 1.951 s]
  Range (min … max):    8.934 s …  9.251 s    10 runs

Summary
  bazel-bin/main/sorbet --parser=prism --stop-after=parser test/testdata ran
    1.11 ± 0.01 times faster than bazel-bin/main/sorbet --parser=sorbet --stop-after=parser test/testdata

Benchmark 3: prism regression tests, whole pipeline

Benchmark 1: bazel-bin/main/sorbet --parser=sorbet test/prism_regression
  Time (mean ± σ):     841.8 ms ±   8.1 ms    [User: 1593.8 ms, System: 119.3 ms]
  Range (min … max):   831.6 ms … 855.6 ms    10 runs

Benchmark 2: bazel-bin/main/sorbet --parser=prism test/prism_regression
  Time (mean ± σ):     841.2 ms ±   7.9 ms    [User: 1618.4 ms, System: 102.3 ms]
  Range (min … max):   831.3 ms … 854.8 ms    10 runs

Summary
  bazel-bin/main/sorbet --parser=prism test/prism_regression ran
    1.00 ± 0.01 times faster than bazel-bin/main/sorbet --parser=sorbet test/prism_regression

@egiurleo egiurleo marked this pull request as draft July 16, 2024 21:25
# Read all files in the benchmarks directory to warm up the file system cache
for i in {1..10}
do
cat ../yjit-bench/benchmarks/**/*.rb > /dev/null
Copy link
Author

Choose a reason for hiding this comment

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

This was Alex M's idea -- basically warm up the file system cache by reading the benchmark files a few times. I've found that it significantly improves the accuracy of the benchmarks on the first run!

Copy link

Choose a reason for hiding this comment

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

TIL

Choose a reason for hiding this comment

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

This step lowering the variance makes me think the # of times hyperfine is warming up may not be enough. It's not crucial but may be worth playing around with different warmup values.

Copy link
Author

Choose a reason for hiding this comment

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

@KaanOzkan agreed. This is significantly faster than warmup loops, so I've done this for now, but I think it's worth reexamining the approach as we go.

# Read all files in the benchmarks directory to warm up the file system cache
for i in {1..10}
do
cat ../yjit-bench/benchmarks/**/*.rb > /dev/null
Copy link

Choose a reason for hiding this comment

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

TIL

Copy link

@amomchilov amomchilov left a comment

Choose a reason for hiding this comment

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

Great!

egiurleo added 2 commits July 19, 2024 12:28
These benchmarks will help us measure the progress of the prism in Sorbet project.
While they can be run from any machine, for "official" results, they should be run
on an AWS bare metal instance. Results should be added to the prism_benchmarks/data
directory.
@egiurleo egiurleo marked this pull request as ready for review July 19, 2024 17:37
@egiurleo egiurleo changed the title WIP: Prism benchmarks Prism benchmarks Jul 19, 2024
@egiurleo egiurleo merged commit b5ee36a into proj-parsing-w-prism-in-sorbet Jul 19, 2024
1 check passed
@egiurleo egiurleo deleted the emily/benchmarks branch July 19, 2024 19:26
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.

4 participants