-
Notifications
You must be signed in to change notification settings - Fork 899
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
Lower the memory allocations #1188
Lower the memory allocations #1188
Conversation
5782dba
to
2d09f08
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.
Awesome! Thanks for working on this. |
Said another way, I'd be a lot more comfortable reviewing this if existing tests can be kept exactly the same. |
2d09f08
to
a0eb617
Compare
Reverted the changes on tests, @jaredbeck please revisit. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sergey, I've finished my first review. Generally speaking, I like the direction this is going.
In this first review, I've focused on getting more information about some things I don't understand, and trying to limit the scope. It's a big PR, so if you don't mind splitting it up a bit, as I suggest below, that would be very helpful.
In future reviews, I'll look more closely at some of the logic, and I'll be running your benchmarks locally.
spec/paper_trail/association_reify_error_behaviour/error_spec.rb
Outdated
Show resolved
Hide resolved
expect(&version_building).to allocate_less_than(35).kilobytes | ||
end | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's very cool that you were able to write these benchmarks as tests. I've never worked on a project with such tests, but I'm willing to try it. My only concern would be if, in the future, memory usage inside rails increases (in a way we cannot control) causing these tests to fail. If it becomes painful in the future, we may need to separate these benchmarks from the test suite.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any optimization efforts become to be mindless without such kind of tests :)
Any next PR can easily ruin all the winnings.
As for the third-party changes, which are really out of our control - at least we will know about the problems with them. We can mark such particular gems and versions as ineffective
both in readme and tests for example.
In general you're right, the life will be harder with these tests :)
"expected that example will allocate less than #{expected}#{@scale},"\ | ||
" but allocated #{@allocated}#{@scale}" | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did not know the RSpec matcher API was so flexible. This is pretty great.
44474b2
to
6966f83
Compare
@jaredbeck please take a look at https://travis-ci.org/paper-trail-gem/paper_trail/builds/505655659 As you can see, the removal of #1189 is strongly affect to performance. I'm forced to make more pessimistic assertions for this PR. |
6966f83
to
77e9174
Compare
@jaredbeck it is ready for the next review ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Second review: Now that #1189 has been merged, please rebase and restore the memory numbers in the test.
There probably won't be a need for a third review, thank you for your work on this so far. Splitting it up into smaller pieces was very helpful, thanks.
It prevents the repeating hashes creation during the calculation of `object` and `object_changes`. The real-life case, discovered with a help of `memory_profiler` gem: 1. It saves `~35Mb` per bulk of 100 typical objects like `User`; 2. It saves `~875Mb` per Sidekiq process full of bulk jobs like P1, under default concurrency 25.
77e9174
to
770d673
Compare
done, please revisit ) Thank you for assistance during this journey ) |
I'm going to make If you'd like to discuss some ideas for the public API, please email me (jared@jaredbeck.com) as we have temporarily disabled GH issues. |
Released as 10.2.1 |
It prevents the repeating hashes creation during the calculation of
object
andobject_changes
.The real-life case, discovered with a help of
memory_profiler
gem:~35Mb
per bulk of 100 typical objects likeUser
;~875Mb
per Sidekiq process full of bulk jobs like P1, under default concurrency 25.As a part of RAM optimization we do:
PaperTrail::Events::Base
methods;changed_attributes
for AR < 5.1;Class.new
instead ofassociation.build
.The record's association cache will be invalidated on the way by
association.reset
, so no any explicitversions.reload
calls are needed now.master
(if not - rebase it).code introduces user-observable changes.
and description in grammatically correct, complete sentences.