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
4.2 perf: AR new with serialized attrs up to 10x slower #18029
Comments
I have a quick WIP optimization: mfazekas@1800232 |
Just confirming using IPS instead:
|
Worth noting that the patch above doesn't do much for you if the serialized attr isn't nil. Modified test script here. |
Calling `changed_attributes` will ultimately check if every mutable attribute has changed in place. Since this gets called whenever an attribute is assigned, it's extremely slow. Instead, we can avoid this calculation until we actually need it. Fixes #18029
Thanks for the report. The fix will be included in 4.2.1 |
Thanks @sgrif! |
Also, using the benchmark provided, I'm seeing a significant speed-up on 4.2 after this change. 😁 master (which should reflect 4-2-stable's performance):
4.1:
|
👍 Thank you! |
Thanks! Our rspec suite with 4.2.1pre now about 20% faster than with rails 4.1 (vs 4.2.0 was being 30% slower) |
❤️ !!! |
Calling `changed_attributes` will ultimately check if every mutable attribute has changed in place. Since this gets called whenever an attribute is assigned, it's extremely slow. Instead, we can avoid this calculation until we actually need it. Fixes rails#18029
We're seeing about +30% time increase in execution time, when running our rspec. (this is similiar to what reported at the end of #17472)
Profiling showed much more YAML parse(psych) compared to 4.1.
Given:
puts Benchmark.measure { 3000.times { DummyItem.new } }
is about 0.2 s in rails 4.1 vs 2.2 s in rails 4.2.rc3.
I don't think it affects web app performance much, but since we use factories and not fixtures for testing, the test execution speed suffers.
full testcase: https://gist.github.com/mfazekas/897f857e4367c94b771b
The text was updated successfully, but these errors were encountered: