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

Increase performance in Liquid::Lexer#tokenize #1606

Merged
merged 1 commit into from
Aug 24, 2022
Merged

Increase performance in Liquid::Lexer#tokenize #1606

merged 1 commit into from
Aug 24, 2022

Conversation

Watson1978
Copy link
Contributor

To obtain String Literal, the regular expression might be executed at two times.
It would be slightly faster to run them all at once using Regexp.union.

before after result
parse 63.418 65.183 1.028x
render 195.389 195.648 -
parse & render 46.091 46.917 1.018x

Environment

  • MacBook Pro (14 inch, 2021)
  • macOS 13.0 Beta
  • Apple M1 Max
  • Ruby 3.1.2

Before

Running benchmark for 10 seconds (with 5 seconds warmup).

Warming up --------------------------------------
              parse:     6.000  i/100ms
             render:    19.000  i/100ms
     parse & render:     4.000  i/100ms
Calculating -------------------------------------
              parse:     63.418  (± 0.0%) i/s -    636.000  in  10.028939s
             render:    195.389  (± 0.5%) i/s -      1.957k in  10.016466s
     parse & render:     46.091  (± 0.0%) i/s -    464.000  in  10.067445s

After

Running benchmark for 10 seconds (with 5 seconds warmup).

Warming up --------------------------------------
              parse:     6.000  i/100ms
             render:    19.000  i/100ms
     parse & render:     4.000  i/100ms
Calculating -------------------------------------
              parse:     65.183  (± 0.0%) i/s -    654.000  in  10.033549s
             render:    195.648  (± 1.0%) i/s -      1.957k in  10.003511s
     parse & render:     46.917  (± 0.0%) i/s -    472.000  in  10.060782s

To obtain String Literal, the regular expression might be executed at two times.
It would be slightly faster to run them all at once using `Regexp.union`.

−               | before   | after   | result
--               | --       | --      | --
parse            | 63.418   | 65.183  | 1.028x
render           | 195.389  | 195.648 | -
parse & render   | 46.091   | 46.917  | 1.018x

### Environment
- MacBook Pro (14 inch, 2021)
- macOS 13.0 Beta
- Apple M1 Max
- Ruby 3.1.2

### Before
```
Running benchmark for 10 seconds (with 5 seconds warmup).

Warming up --------------------------------------
              parse:     6.000  i/100ms
             render:    19.000  i/100ms
     parse & render:     4.000  i/100ms
Calculating -------------------------------------
              parse:     63.418  (± 0.0%) i/s -    636.000  in  10.028939s
             render:    195.389  (± 0.5%) i/s -      1.957k in  10.016466s
     parse & render:     46.091  (± 0.0%) i/s -    464.000  in  10.067445s
```

### After
```
Running benchmark for 10 seconds (with 5 seconds warmup).

Warming up --------------------------------------
              parse:     6.000  i/100ms
             render:    19.000  i/100ms
     parse & render:     4.000  i/100ms
Calculating -------------------------------------
              parse:     65.183  (± 0.0%) i/s -    654.000  in  10.033549s
             render:    195.648  (± 1.0%) i/s -      1.957k in  10.003511s
     parse & render:     46.917  (± 0.0%) i/s -    472.000  in  10.060782s
```
@dylanahsmith dylanahsmith merged commit 98e146e into Shopify:master Aug 24, 2022
@Watson1978 Watson1978 deleted the performance-lexer-tokenize branch August 24, 2022 20:26
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.

2 participants