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

Change loop in parse_attributes to while true. #109

Merged
merged 1 commit into from
Jan 31, 2024

Conversation

naitoh
Copy link
Contributor

@naitoh naitoh commented Jan 31, 2024

Why

loop is slower than while true.

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.186      11.304        17.395       17.450 i/s -     100.000 times in 8.940144s 8.846590s 5.748718s 5.730793s
                 sax     30.811      31.629        47.352       48.040 i/s -     100.000 times in 3.245601s 3.161619s 2.111854s 2.081594s
                pull     35.793      36.621        56.924       57.313 i/s -     100.000 times in 2.793829s 2.730693s 1.756732s 1.744812s
              stream     33.157      34.757        46.792       50.536 i/s -     100.000 times in 3.015940s 2.877088s 2.137106s 1.978787s

Comparison:
                              dom
         after(YJIT):        17.4 i/s
        before(YJIT):        17.4 i/s - 1.00x  slower
               after:        11.3 i/s - 1.54x  slower
              before:        11.2 i/s - 1.56x  slower

                              sax
         after(YJIT):        48.0 i/s
        before(YJIT):        47.4 i/s - 1.01x  slower
               after:        31.6 i/s - 1.52x  slower
              before:        30.8 i/s - 1.56x  slower

                             pull
         after(YJIT):        57.3 i/s
        before(YJIT):        56.9 i/s - 1.01x  slower
               after:        36.6 i/s - 1.57x  slower
              before:        35.8 i/s - 1.60x  slower

                           stream
         after(YJIT):        50.5 i/s
        before(YJIT):        46.8 i/s - 1.08x  slower
               after:        34.8 i/s - 1.45x  slower
              before:        33.2 i/s - 1.52x  slower

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

## Why

loop is slower than `while true`.

## 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.186      11.304        17.395       17.450 i/s -     100.000 times in 8.940144s 8.846590s 5.748718s 5.730793s
                 sax     30.811      31.629        47.352       48.040 i/s -     100.000 times in 3.245601s 3.161619s 2.111854s 2.081594s
                pull     35.793      36.621        56.924       57.313 i/s -     100.000 times in 2.793829s 2.730693s 1.756732s 1.744812s
              stream     33.157      34.757        46.792       50.536 i/s -     100.000 times in 3.015940s 2.877088s 2.137106s 1.978787s

Comparison:
                              dom
         after(YJIT):        17.4 i/s
        before(YJIT):        17.4 i/s - 1.00x  slower
               after:        11.3 i/s - 1.54x  slower
              before:        11.2 i/s - 1.56x  slower

                              sax
         after(YJIT):        48.0 i/s
        before(YJIT):        47.4 i/s - 1.01x  slower
               after:        31.6 i/s - 1.52x  slower
              before:        30.8 i/s - 1.56x  slower

                             pull
         after(YJIT):        57.3 i/s
        before(YJIT):        56.9 i/s - 1.01x  slower
               after:        36.6 i/s - 1.57x  slower
              before:        35.8 i/s - 1.60x  slower

                           stream
         after(YJIT):        50.5 i/s
        before(YJIT):        46.8 i/s - 1.08x  slower
               after:        34.8 i/s - 1.45x  slower
              before:        33.2 i/s - 1.52x  slower

```

- YJIT=ON : 1.00x - 1.08x faster
- YJIT=OFF : 1.01x - 1.04x faster
@kou kou merged commit 7e4049f into ruby:master Jan 31, 2024
38 of 39 checks passed
@kou
Copy link
Member

kou commented Jan 31, 2024

I merged this but I don't want to do this optimization as much as possible personally...

@naitoh naitoh deleted the parse_attibutes_while branch January 31, 2024 08:22
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