-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Speed up the lexer for Ruby 3.4+ (#1832)
* Speed up lexing * Bump msrv to 3.0 (from 2.7) * Normalize test for ruby-head compat * Fix bug when parsing negative numbers
- Loading branch information
Showing
12 changed files
with
246 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,4 @@ pkg | |
.rvmrc | ||
.bundle | ||
.byebug_history | ||
Gemfile.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
3.3.0 | ||
3.3.4 |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# frozen_string_literal: true | ||
|
||
require "benchmark/ips" | ||
|
||
# benchmark liquid lexing | ||
|
||
require 'liquid' | ||
|
||
RubyVM::YJIT.enable | ||
|
||
EXPRESSIONS = [ | ||
"foo[1..2].baz", | ||
"12.0", | ||
"foo.bar.based", | ||
"21 - 62", | ||
"foo.bar.baz", | ||
"foo > 12", | ||
"foo < 12", | ||
"foo <= 12", | ||
"foo >= 12", | ||
"foo <> 12", | ||
"foo == 12", | ||
"foo != 12", | ||
"foo contains 12", | ||
"foo contains 'bar'", | ||
"foo != 'bar'", | ||
"'foo' contains 'bar'", | ||
'234089', | ||
"foo | default: -1", | ||
] | ||
|
||
EXPRESSIONS.each do |expr| | ||
lexer_1_result = Liquid::Lexer1.new(expr).tokenize | ||
lexer_2_result = Liquid::Lexer2.new(expr).tokenize | ||
|
||
next if lexer_1_result == lexer_2_result | ||
|
||
warn "Lexer1 and Lexer2 results are different for expression: #{expr}" | ||
warn "expected: #{lexer_1_result}" | ||
warn "got: #{lexer_2_result}" | ||
abort | ||
end | ||
|
||
Benchmark.ips do |x| | ||
x.config(time: 10, warmup: 5) | ||
|
||
x.report("Liquid::Lexer1#tokenize") do | ||
EXPRESSIONS.each do |expr| | ||
l = Liquid::Lexer1.new(expr) | ||
l.tokenize | ||
end | ||
end | ||
|
||
x.report("Liquid::Lexer2#tokenize") do | ||
EXPRESSIONS.each do |expr| | ||
l = Liquid::Lexer2.new(expr) | ||
l.tokenize | ||
end | ||
end | ||
|
||
x.compare! | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.