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

Reuse of Set.new at prefixes variables #157

Merged
merged 2 commits into from
Jun 23, 2024

Conversation

naitoh
Copy link
Contributor

@naitoh naitoh commented Jun 23, 2024

Why?

Set.new() instances of the prefixes variable can be reused, reducing initialization costs.

Result

RUBYLIB= BUNDLER_ORIG_RUBYLIB= /Users/naitoh/.rbenv/versions/3.3.3/bin/ruby -v -S benchmark-driver /Users/naitoh/ghq/github.com/naitoh/rexml/benchmark/parse.yaml
ruby 3.3.3 (2024-06-12 revision f1c7b6f435) [arm64-darwin22]
Calculating -------------------------------------
                         before       after  before(YJIT)  after(YJIT)
                 dom     17.714      17.658        32.898       33.247 i/s -     100.000 times in 5.645176s 5.663160s 3.039707s 3.007755s
                 sax     25.280      25.281        47.483       49.990 i/s -     100.000 times in 3.955694s 3.955534s 2.106006s 2.000389s
                pull     29.048      29.061        59.944       61.498 i/s -     100.000 times in 3.442599s 3.441014s 1.668222s 1.626060s
              stream     28.181      28.440        52.340       55.078 i/s -     100.000 times in 3.548546s 3.516169s 1.910599s 1.815599s

Comparison:
                              dom
         after(YJIT):        33.2 i/s
        before(YJIT):        32.9 i/s - 1.01x  slower
              before:        17.7 i/s - 1.88x  slower
               after:        17.7 i/s - 1.88x  slower

                              sax
         after(YJIT):        50.0 i/s
        before(YJIT):        47.5 i/s - 1.05x  slower
               after:        25.3 i/s - 1.98x  slower
              before:        25.3 i/s - 1.98x  slower

                             pull
         after(YJIT):        61.5 i/s
        before(YJIT):        59.9 i/s - 1.03x  slower
               after:        29.1 i/s - 2.12x  slower
              before:        29.0 i/s - 2.12x  slower

                           stream
         after(YJIT):        55.1 i/s
        before(YJIT):        52.3 i/s - 1.05x  slower
               after:        28.4 i/s - 1.94x  slower
              before:        28.2 i/s - 1.95x  slower

YJIT=ON : 1.01x - 1.05x faster
YJIT=OFF : 0.99x - 1.00x faster

## Why?
Set.new() instances of the prefixes variable can be reused, reducing initialization costs.

## Result
```
RUBYLIB= BUNDLER_ORIG_RUBYLIB= /Users/naitoh/.rbenv/versions/3.3.3/bin/ruby -v -S benchmark-driver /Users/naitoh/ghq/github.com/naitoh/rexml/benchmark/parse.yaml
ruby 3.3.3 (2024-06-12 revision f1c7b6f435) [arm64-darwin22]
Calculating -------------------------------------
                         before       after  before(YJIT)  after(YJIT)
                 dom     17.714      17.658        32.898       33.247 i/s -     100.000 times in 5.645176s 5.663160s 3.039707s 3.007755s
                 sax     25.280      25.281        47.483       49.990 i/s -     100.000 times in 3.955694s 3.955534s 2.106006s 2.000389s
                pull     29.048      29.061        59.944       61.498 i/s -     100.000 times in 3.442599s 3.441014s 1.668222s 1.626060s
              stream     28.181      28.440        52.340       55.078 i/s -     100.000 times in 3.548546s 3.516169s 1.910599s 1.815599s

Comparison:
                              dom
         after(YJIT):        33.2 i/s
        before(YJIT):        32.9 i/s - 1.01x  slower
              before:        17.7 i/s - 1.88x  slower
               after:        17.7 i/s - 1.88x  slower

                              sax
         after(YJIT):        50.0 i/s
        before(YJIT):        47.5 i/s - 1.05x  slower
               after:        25.3 i/s - 1.98x  slower
              before:        25.3 i/s - 1.98x  slower

                             pull
         after(YJIT):        61.5 i/s
        before(YJIT):        59.9 i/s - 1.03x  slower
               after:        29.1 i/s - 2.12x  slower
              before:        29.0 i/s - 2.12x  slower

                           stream
         after(YJIT):        55.1 i/s
        before(YJIT):        52.3 i/s - 1.05x  slower
               after:        28.4 i/s - 1.94x  slower
              before:        28.2 i/s - 1.95x  slower

```

YJIT=ON : 1.01x - 1.05x faster
YJIT=OFF : 0.99x - 1.00x faster
@kou kou merged commit e6e07f2 into ruby:master Jun 23, 2024
61 checks passed
@kou
Copy link
Member

kou commented Jun 23, 2024

Thanks.

@naitoh naitoh deleted the reuse_of_set_new_at_prefixes_variables branch June 23, 2024 11:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants