+14
README.md
+14
README.md
···
2
3
There seems to be some kind of performance regression in Ruby 4.0 which showed up in my project, which I think is centered around regexp matching. I extracted some minimal code from the project, which runs significantly slower on Ruby 4.0 than on 3.4.
4
5
Running on my server, with 1000 loops:
6
7
```
···
23
$ RUBYOPT="--enable-yjit" ruby test.rb 1000
24
1000 * 940 = 940000 records in 13.457106019 -> 69851.57125706079 records/s
25
```
···
2
3
There seems to be some kind of performance regression in Ruby 4.0 which showed up in my project, which I think is centered around regexp matching. I extracted some minimal code from the project, which runs significantly slower on Ruby 4.0 than on 3.4.
4
5
+
#### First version (commit 20923f0028e2c023bd5e48be5118c5f97f4f243a)
6
+
7
Running on my server, with 1000 loops:
8
9
```
···
25
$ RUBYOPT="--enable-yjit" ruby test.rb 1000
26
1000 * 940 = 940000 records in 13.457106019 -> 69851.57125706079 records/s
27
```
28
+
29
+
#### Minimal version (commit ccc62810ac635f3250bebe12a08d79ad5d9dd7f5)
30
+
31
+
With 2,000,000 loops:
32
+
33
+
```
34
+
$ /tmp/ruby34/bin/ruby test.rb 2000000 0
35
+
2000000 loops in 0.752061 -> 2659358.748824896 loops/s
36
+
37
+
$ /tmp/ruby4/bin/ruby test.rb 2000000 0
38
+
2000000 loops in 2.711216 -> 737676.3784220808 loops/s
39
+
```
+4
-12
test.rb
+4
-12
test.rb
···
1
require 'json'
2
3
-
REGEXPS = [
4
-
/linux/i, /debian/i, /ubuntu/i, /\bredhat\b/i, /\bRHEL\b/, /\bSUSE\b/, /\bCentOS\b/, /\bopensuse\b/i,
5
-
/\bslackware\b/i, /\bKDE\b/, /\bGTK\d?\b/, /#GNOME\b/, /\bGNOME\s?\d+/, /\bkde plasma\b/i,
6
-
/apt\-get/, /\bflatpak\b/i, /\b[Xx]org\b/
7
-
]
8
9
-
posts = JSON.load(File.read('atprotocoldev.json'))
10
loops = ARGV[0].to_i
11
12
if loops <= 0
···
17
time_start = Time.now
18
19
loops.times do
20
-
posts.each do |text|
21
-
match = REGEXPS.any? { |r| text =~ r }
22
-
end
23
end
24
25
time_end = Time.now
26
-
27
-
total = loops * posts.length
28
total_time = time_end - time_start
29
30
-
puts "#{loops} * #{posts.length} = #{total} records in #{total_time} -> #{total / total_time} records/s"
···
1
require 'json'
2
3
+
regexp = /\bslackware\b/i
4
+
test_post = "This isn’t a very long string – but it includes some non-ASCII™ characters…"
5
6
loops = ARGV[0].to_i
7
8
if loops <= 0
···
13
time_start = Time.now
14
15
loops.times do
16
+
test_post =~ regexp
17
end
18
19
time_end = Time.now
20
total_time = time_end - time_start
21
22
+
puts "#{loops} loops in #{total_time} -> #{loops / total_time} loops/s"