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 calls to StringScanner.new() #108

Merged
merged 1 commit into from
Jan 31, 2024
Merged

Conversation

naitoh
Copy link
Contributor

@naitoh naitoh commented Jan 29, 2024

Why

StringScanner.new() instances can be reused within parse_attributes, reducing initialization costs.

Benchmark

RUBYLIB= BUNDLER_ORIG_RUBYLIB= /Users/naitoh/.rbenv/versions/3.3.0/bin/ruby -v -S benchmark-driver /Users/naitoh/ghq/github.com/naitoh/rexml/benchmark/parse.yaml
ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [arm64-darwin22]
Calculating -------------------------------------
                         before       after  before(YJIT)  after(YJIT)
                 dom     11.018      11.207        17.059       16.660 i/s -     100.000 times in 9.075992s 8.923280s 5.861969s 6.002555s
                 sax     29.843      30.821        45.518       47.505 i/s -     100.000 times in 3.350909s 3.244524s 2.196940s 2.105037s
                pull     34.480      35.937        52.816       57.098 i/s -     100.000 times in 2.900205s 2.782632s 1.893370s 1.751378s
              stream     32.430      33.516        46.247       48.412 i/s -     100.000 times in 3.083536s 2.983607s 2.162288s 2.065584s

Comparison:
                              dom
        before(YJIT):        17.1 i/s
         after(YJIT):        16.7 i/s - 1.02x  slower
               after:        11.2 i/s - 1.52x  slower
              before:        11.0 i/s - 1.55x  slower

                              sax
         after(YJIT):        47.5 i/s
        before(YJIT):        45.5 i/s - 1.04x  slower
               after:        30.8 i/s - 1.54x  slower
              before:        29.8 i/s - 1.59x  slower

                             pull
         after(YJIT):        57.1 i/s
        before(YJIT):        52.8 i/s - 1.08x  slower
               after:        35.9 i/s - 1.59x  slower
              before:        34.5 i/s - 1.66x  slower

                           stream
         after(YJIT):        48.4 i/s
        before(YJIT):        46.2 i/s - 1.05x  slower
               after:        33.5 i/s - 1.44x  slower
              before:        32.4 i/s - 1.49x  slower

  • YJIT=ON : 1.02x - 1.08x faster
  • YJIT=OFF : 1.01x - 1.04x faster

[Why]
StringScanner.new() instances can be reused within parse_attributes, reducing initialization costs.

## Benchmark

```
RUBYLIB= BUNDLER_ORIG_RUBYLIB= /Users/naitoh/.rbenv/versions/3.3.0/bin/ruby -v -S benchmark-driver /Users/naitoh/ghq/github.com/naitoh/rexml/benchmark/parse.yaml
ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [arm64-darwin22]
Calculating -------------------------------------
                         before       after  before(YJIT)  after(YJIT)
                 dom     11.018      11.207        17.059       16.660 i/s -     100.000 times in 9.075992s 8.923280s 5.861969s 6.002555s
                 sax     29.843      30.821        45.518       47.505 i/s -     100.000 times in 3.350909s 3.244524s 2.196940s 2.105037s
                pull     34.480      35.937        52.816       57.098 i/s -     100.000 times in 2.900205s 2.782632s 1.893370s 1.751378s
              stream     32.430      33.516        46.247       48.412 i/s -     100.000 times in 3.083536s 2.983607s 2.162288s 2.065584s

Comparison:
                              dom
        before(YJIT):        17.1 i/s
         after(YJIT):        16.7 i/s - 1.02x  slower
               after:        11.2 i/s - 1.52x  slower
              before:        11.0 i/s - 1.55x  slower

                              sax
         after(YJIT):        47.5 i/s
        before(YJIT):        45.5 i/s - 1.04x  slower
               after:        30.8 i/s - 1.54x  slower
              before:        29.8 i/s - 1.59x  slower

                             pull
         after(YJIT):        57.1 i/s
        before(YJIT):        52.8 i/s - 1.08x  slower
               after:        35.9 i/s - 1.59x  slower
              before:        34.5 i/s - 1.66x  slower

                           stream
         after(YJIT):        48.4 i/s
        before(YJIT):        46.2 i/s - 1.05x  slower
               after:        33.5 i/s - 1.44x  slower
              before:        32.4 i/s - 1.49x  slower

```

- YJIT=ON : 1.02x - 1.08x faster
- YJIT=OFF : 1.01x - 1.04x faster
@kou kou merged commit 51217db into ruby:master Jan 31, 2024
39 checks passed
@kou
Copy link
Member

kou commented Jan 31, 2024

Thanks!

@naitoh naitoh deleted the string_raw_attributes branch January 31, 2024 07:36
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