Thanks to visit codestin.com
Credit goes to github.com

Skip to content

YJIT: Specialize String#[] (String#slice) with fixnum arguments #12069

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

Merged
merged 2 commits into from
Nov 13, 2024

Conversation

rwstauner
Copy link
Contributor

String#[] is in the top few C calls of several YJIT benchmarks:
liquid-compile rubocop mail sudoku

While it has 5 different argument scenarios the most common by far are one fixnum and two fixnums
so we match those argument types and write the ccall directly to the corresponding C function.

This speeds up these benchmarks by 1-5%.

This is similar to the String#byteslice specialization #9939
but it works harder to find the type info which was necessary for the specialization to apply in the large generated code of the mail gem.

bench           ruby-master (ms)  stddev (%)  ruby-yjit-ss3 (ms)  stddev (%)  ruby-yjit-ss3 1st itr  ruby-master/ruby-yjit-ss3
liquid-compile  495.7             0.1         493.4               0.1         1.03                   1.00
mail            211.3             0.1         199.5               0.3         1.00                   1.06
rubocop         902.2             0.0         897.1               0.1         0.99                   1.01
sudoku          1420.0            0.0         1409.4              0.0         1.00                   1.01

@matzbot matzbot requested a review from a team November 12, 2024 20:08
@rwstauner rwstauner force-pushed the rwstauner/yjit-string-slice branch from c8bad4f to 0ad866a Compare November 12, 2024 20:10
Copy link
Contributor

@maximecb maximecb left a comment

Choose a reason for hiding this comment

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

Well done Randy 👏

@rwstauner rwstauner force-pushed the rwstauner/yjit-string-slice branch from 0ad866a to 15096d4 Compare November 12, 2024 21:04
@rwstauner rwstauner force-pushed the rwstauner/yjit-string-slice branch 3 times, most recently from 289a87b to 9d0d3d4 Compare November 13, 2024 15:38
rwstauner and others added 2 commits November 13, 2024 09:53
String#[] is in the top few C calls of several YJIT benchmarks:
liquid-compile rubocop mail sudoku

This speeds up these benchmarks by 1-2%.
In the large generated code of the mail gem the context doesn't have
the type info.  In that case if we peek at the stack and add a guard
we can still apply the specialization
and it speeds up the mail benchmark by 5%.

Co-authored-by: Maxime Chevalier-Boisvert <[email protected]>
Co-authored-by: Takashi Kokubun (k0kubun) <[email protected]>
@rwstauner rwstauner force-pushed the rwstauner/yjit-string-slice branch from 9d0d3d4 to df4fe2f Compare November 13, 2024 16:53
@maximecb maximecb merged commit beafae9 into ruby:master Nov 13, 2024
69 checks passed
@maximecb maximecb deleted the rwstauner/yjit-string-slice branch November 13, 2024 17:25
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.

3 participants