-
Notifications
You must be signed in to change notification settings - Fork 124
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
Potential performance regression with Ruby 3.3 #336
Comments
Cannot run caxlsx/lib/axlsx/stylesheet/styles.rb Line 503 in a1b4439
|
I've found a significant difference in how MatchData is handled in caxlsx/lib/axlsx/workbook/worksheet/cell.rb Line 532 in a1b4439
Minimal code to reproduce the difference:
Ruby 3.2.2
Ruby 3.3.0
Could be other places as well, but it seems to be a nice spot to start the investigation |
Thanks. I'm able to run profiler against this reduced test case. Bringing it to the extreme, it happens on 3.3 when there is not a match No matchrequire 'memory_profiler'
report = MemoryProfiler.report do
/\A[A-Z]+\Z/.match('1')
end
report.pretty_print Ruby 3.2:
Ruby 3.3:
Match (
|
I did the bisect, here are the results: ruby/ruby@7193b40 seems to be the culprit.
where the script is almost the same as you posted before: matchdata.rb filerequire 'memory_profiler'
v = '1'
report = MemoryProfiler.report { /\A[A-Z]+\Z/.match(v) }
exit report.total_allocated_memsize git bisect log
How should we proceed with this one? |
Sorry, I'm not sure, this is beyond my knowledge It looks both slower and uses more memory than 3.2. Is it possible that this is an undesired regression in Ruby? %i[ips memory].each do |benchmark|
Benchmark.send(benchmark) do |x|
x.report('test') { /\A[A-Z]+\Z/.match('1') }
x.compare!
end
end
Benchmarks in case of match
|
I looked into this and created a pull request for ruby here: ruby/ruby#9398. There is also a Ruby ticket here: https://bugs.ruby-lang.org/issues/20104 |
Thanks @luke-gru! I've followed the PR to understand the fix and I've seen that it has been approved. Should it be also backported to 3.3.x stable branch? @kiskoza would it be possible for you to run the full |
It looks okay again 👍 Thanks @luke-gru for the quick fix 🚀 Tested on
|
I've compared performance between 3.2.2 and 3.4.0-dev and it looks almost the same, with a slightly advantage towards 3.4, except for
|
It has been resolved already on Ruby's main branch and the backport seems to be on its way, nothing to do from our side. We should keep this ticket open until Ruby 3.3.1 arrives to verify the fix. |
Does it seem likely that the unnecessary match allocation is responsible for the unbounded memory growth described here? I am not terribly familiar with the MRI internals, but I'd guess that the match is allocated on the garbage collected heap, so I wouldn't expect this actually to leak memory. I ask, because my company's application is having some OOM issues after upgrading to 3.3.0, and I'm trying to figure out if we should revert to 3.2 for now. |
@97jaz Like you mentioned, the MatchData object lives on the ruby heap so it wouldn't leak memory. Maybe try opening a ticket on redmine.ruby-lang.org with a detailed account of the problem and how much memory your environment has. Reverting also might not be a bad idea. |
Ruby 3.3.1 got released 🎉 The results seems to be okay when running
|
Ruby 3.3.0(x64) Memory
Also tested against
ruby 3.4.0dev (2023-12-30T03:14:38Z master 8e32c01742) [arm64-darwin23]
Ruby 3.2.2 (x64) Memory
1.47x memory
Also, there seems to be a performance degradation in IPS
Ruby 3.3.0 (x64) IPS
Ruby 3.2.2 (x64) IPS
1.03x slower
Ref: ruby/ruby#8123
The text was updated successfully, but these errors were encountered: