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

Reduce the number of branches in jit_exec #6722

Merged
merged 3 commits into from Nov 14, 2022
Merged

Conversation

k0kubun
Copy link
Member

@k0kubun k0kubun commented Nov 13, 2022

The primary purpose of this is the readability of jit_exec. I confirmed that this doesn't slow down both JITs.

Benchmark

YJIT

before: ruby 3.2.0dev (2022-11-13T22:41:08Z master e377875cff) +YJIT [x86_64-linux]
after: ruby 3.2.0dev (2022-11-13T22:48:13Z jit-exec f809f4effd) +YJIT [x86_64-linux]

----------  -----------  ----------  ----------  ----------  ------------  -------------
bench       before (ms)  stddev (%)  after (ms)  stddev (%)  before/after  after 1st itr
railsbench  1113.8       1.7         1070.3      1.8         1.04          1.01
----------  -----------  ----------  ----------  ----------  ------------  -------------
$ ./run_benchmarks.rb railsbench -e "before::/opt/rubies/before/bin/ruby --yjit" -e "after::/opt/rubies/after/bin/ruby --yjit"
Running benchmark "railsbench" (1/1)
setarch x86_64 -R taskset -c 7 /opt/rubies/before/bin/ruby --yjit -I ./harness benchmarks/railsbench/benchmark.rb
ruby 3.2.0dev (2022-11-13T22:41:08Z master e377875cff) +YJIT [x86_64-linux]
Command: bundle check 2> /dev/null || bundle install
The Gemfile's dependencies are satisfied
Command: bin/rails db:migrate db:seed
Deleted all 100 posts
Creating 100 posts....................................................................................................
itr #1: 1233ms
itr #2: 1053ms
itr #3: 1075ms
itr #4: 1110ms
itr #5: 1086ms
itr #6: 1076ms
itr #7: 1077ms
itr #8: 1076ms
itr #9: 1126ms
itr #10: 1112ms
itr #11: 1109ms
itr #12: 1117ms
itr #13: 1084ms
itr #14: 1144ms
itr #15: 1079ms
itr #16: 1127ms
itr #17: 1092ms
itr #18: 1121ms
itr #19: 1124ms
itr #20: 1128ms
itr #21: 1113ms
itr #22: 1110ms
itr #23: 1147ms
itr #24: 1091ms
itr #25: 1081ms
Average of last 10, non-warmup iters: 1113ms
Running benchmark "railsbench" (1/1)
setarch x86_64 -R taskset -c 7 /opt/rubies/after/bin/ruby --yjit -I ./harness benchmarks/railsbench/benchmark.rb
ruby 3.2.0dev (2022-11-13T22:48:13Z jit-exec f809f4effd) +YJIT [x86_64-linux]
Command: bundle check 2> /dev/null || bundle install
The Gemfile's dependencies are satisfied
Command: bin/rails db:migrate db:seed
Deleted all 100 posts
Creating 100 posts....................................................................................................
itr #1: 1217ms
itr #2: 1073ms
itr #3: 1109ms
itr #4: 1109ms
itr #5: 1110ms
itr #6: 1109ms
itr #7: 1080ms
itr #8: 1104ms
itr #9: 1108ms
itr #10: 1039ms
itr #11: 1046ms
itr #12: 1070ms
itr #13: 1068ms
itr #14: 1078ms
itr #15: 1104ms
itr #16: 1074ms
itr #17: 1070ms
itr #18: 1072ms
itr #19: 1086ms
itr #20: 1073ms
itr #21: 1069ms
itr #22: 1045ms
itr #23: 1033ms
itr #24: 1070ms
itr #25: 1108ms
Average of last 10, non-warmup iters: 1070ms
Total time spent benchmarking: 58s

end_time: 2022-11-13 14:50:26 PST (-0800)
before: ruby 3.2.0dev (2022-11-13T22:41:08Z master e377875cff) +YJIT [x86_64-linux]
after: ruby 3.2.0dev (2022-11-13T22:48:13Z jit-exec f809f4effd) +YJIT [x86_64-linux]

----------  -----------  ----------  ----------  ----------  ------------  -------------
bench       before (ms)  stddev (%)  after (ms)  stddev (%)  before/after  after 1st itr
railsbench  1113.8       1.7         1070.3      1.8         1.04          1.01
----------  -----------  ----------  ----------  ----------  ------------  -------------
Legend:
- before/after: ratio of before/after time. Higher is better for after. Above 1 represents a speedup.
- after 1st itr: ratio of before/after time for the first benchmarking iteration.

MJIT

before: ruby 3.2.0dev (2022-11-13T22:41:08Z master e377875cff) +MJIT [x86_64-linux]
after: ruby 3.2.0dev (2022-11-13T22:48:13Z jit-exec f809f4effd) +MJIT [x86_64-linux]

---------  -----------  ----------  ----------  ----------  ------------  -------------
bench      before (ms)  stddev (%)  after (ms)  stddev (%)  before/after  after 1st itr
optcarrot  1467.7       1.4         1448.2      1.0         1.01          1.00
---------  -----------  ----------  ----------  ----------  ------------  -------------
Running benchmark "optcarrot" (1/1)
setarch x86_64 -R taskset -c 7 /opt/rubies/before/bin/ruby --mjit-max-cache\=100 -I ./harness benchmarks/optcarrot/benchmark.rb
ruby 3.2.0dev (2022-11-13T22:41:08Z master e377875cff) +MJIT [x86_64-linux]
itr #1: 4406ms
itr #2: 2782ms
itr #3: 2858ms
itr #4: 2718ms
itr #5: 2447ms
itr #6: 2421ms
itr #7: 2374ms
itr #8: 2402ms
itr #9: 2446ms
itr #10: 2927ms
itr #11: 3010ms
itr #12: 3034ms
itr #13: 2477ms
itr #14: 1481ms
itr #15: 1483ms
itr #16: 1476ms
itr #17: 1478ms
itr #18: 1484ms
itr #19: 1480ms
itr #20: 1436ms
itr #21: 1451ms
itr #22: 1440ms
itr #23: 1448ms
itr #24: 1491ms
itr #25: 1488ms
Average of last 10, non-warmup iters: 1467ms
Running benchmark "optcarrot" (1/1)
setarch x86_64 -R taskset -c 7 /opt/rubies/after/bin/ruby --mjit-max-cache\=100 -I ./harness benchmarks/optcarrot/benchmark.rb
ruby 3.2.0dev (2022-11-13T22:48:13Z jit-exec f809f4effd) +MJIT [x86_64-linux]
itr #1: 4390ms
itr #2: 2788ms
itr #3: 2852ms
itr #4: 2688ms
itr #5: 2513ms
itr #6: 2475ms
itr #7: 2368ms
itr #8: 2462ms
itr #9: 2424ms
itr #10: 2901ms
itr #11: 3010ms
itr #12: 2995ms
itr #13: 2454ms
itr #14: 1466ms
itr #15: 1461ms
itr #16: 1465ms
itr #17: 1460ms
itr #18: 1455ms
itr #19: 1463ms
itr #20: 1427ms
itr #21: 1430ms
itr #22: 1430ms
itr #23: 1433ms
itr #24: 1454ms
itr #25: 1461ms
Average of last 10, non-warmup iters: 1448ms
Total time spent benchmarking: 109s

end_time: 2022-11-13 14:55:12 PST (-0800)
before: ruby 3.2.0dev (2022-11-13T22:41:08Z master e377875cff) +MJIT [x86_64-linux]
after: ruby 3.2.0dev (2022-11-13T22:48:13Z jit-exec f809f4effd) +MJIT [x86_64-linux]

---------  -----------  ----------  ----------  ----------  ------------  -------------
bench      before (ms)  stddev (%)  after (ms)  stddev (%)  before/after  after 1st itr
optcarrot  1467.7       1.4         1448.2      1.0         1.01          1.00
---------  -----------  ----------  ----------  ----------  ------------  -------------
Legend:
- before/after: ratio of before/after time. Higher is better for after. Above 1 represents a speedup.
- after 1st itr: ratio of before/after time for the first benchmarking iteration.

@k0kubun k0kubun force-pushed the jit-exec branch 2 times, most recently from caf20b3 to e6f890c Compare November 13, 2022 22:42
@k0kubun k0kubun marked this pull request as ready for review November 13, 2022 22:57
@matzbot matzbot requested a review from a team November 13, 2022 22:57
@k0kubun k0kubun merged commit 3dd4e38 into ruby:master Nov 14, 2022
@k0kubun k0kubun deleted the jit-exec branch November 14, 2022 04:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
1 participant