Skip to content

Speed up the lexer for Ruby 3.4+#1832

Merged
ianks merged 4 commits into
mainfrom
lexer-2
Oct 23, 2024
Merged

Speed up the lexer for Ruby 3.4+#1832
ianks merged 4 commits into
mainfrom
lexer-2

Conversation

@ianks
Copy link
Copy Markdown
Contributor

@ianks ianks commented Oct 23, 2024

This PR speeds up lexing by making using of some new strscan features when available, namely StringScanner#peek_byte.

Benchmarks

Local

Comparison of be rake benchmark:strict on Ruby 3.4:

  • old parse: 72.452 (± 4.1%) i/s (13.80 ms/i) - 2.170k in 30.029157s
  • new parse: 92.409 (± 1.1%) i/s (10.82 ms/i) - 2.772k in 30.002144s

Production

I ran the two in A/B style against some production traffic. The following measures Liquid::Template.parse with the new lexer:

image

1: Old
2: New

To make this work smoothly with CI and such, I needed to bump min version to Ruby 3.0 and remove Gemfile.lock, which need to be updated anyway.

@ianks ianks merged commit b355378 into main Oct 23, 2024
andrykonchin pushed a commit to andrykonchin/liquid that referenced this pull request Feb 24, 2025
* Speed up lexing

* Bump msrv to 3.0 (from 2.7)

* Normalize test for ruby-head compat

* Fix bug when parsing negative numbers
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