Test for Ruby 4.0 performance regression
1# Ruby 4.0 regexp test 2 3There 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 7Running on my server, with 1000 loops: 8 9``` 10$ asdf shell ruby 3.4.8 11$ ruby test.rb 1000 121000 * 940 = 940000 records in 7.439838799 -> 126346.82355299778 records/s 13$ asdf shell ruby 4.0.0 14$ ruby test.rb 1000 151000 * 940 = 940000 records in 13.67647823 -> 68731.14439198723 records/s 16``` 17 18With YJIT: 19 20``` 21$ asdf shell ruby 3.4.8 22$ RUBYOPT="--enable-yjit" ruby test.rb 1000 231000 * 940 = 940000 records in 7.20592409 -> 130448.22402507435 records/s 24$ asdf shell ruby 4.0.0 25$ RUBYOPT="--enable-yjit" ruby test.rb 1000 261000 * 940 = 940000 records in 13.457106019 -> 69851.57125706079 records/s 27``` 28 29#### Minimal version (commit ccc62810ac635f3250bebe12a08d79ad5d9dd7f5) 30 31With 2,000,000 loops: 32 33``` 34$ /tmp/ruby34/bin/ruby test.rb 2000000 0 352000000 loops in 0.752061 -> 2659358.748824896 loops/s 36 37$ /tmp/ruby4/bin/ruby test.rb 2000000 0 382000000 loops in 2.711216 -> 737676.3784220808 loops/s 39```