-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
HHH-19850 replace arraylist by bitSet when resolving dirty attribute indexes #11104
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
base: main
Are you sure you want to change the base?
HHH-19850 replace arraylist by bitSet when resolving dirty attribute indexes #11104
Conversation
…indexes This aims to reduce memory usage by reducing allocations when resolving
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.
Thanks for the contribution @Meehdi, I left a few comments.
As with any primarily performance-related changes, we usually run (micro)benchmarks and profiling to verify we are actually seeing improvements in real-world scenarios, see for example this repository.
Have you tried verifying if there is a significant gain (or loss) in performance with this change?
if ( propertyUpdateability[position] && !fields.get( position ) ) { | ||
fields.set( position ); |
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.
No need to check !fields.get( position )
, as setting an already-set bit is idempotent.
if ( index != null && propertyUpdateability[index] && !fields.get( index ) ) { | ||
fields.set( index ); |
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.
See previous comment
@JiraKey("HHH-19850") | ||
public class AbstractEntityPersisterTest extends BaseCoreFunctionalTestCase { | ||
|
||
private AbstractEntityPersister persister; |
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.
We already have existing tests which should check the behavior of the method you changed, no need to create one which artificially tests it through internal-only calls. It would be great if you could modify an existing one instead, adding any assertions if needed.
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.
Yeah I see !
Can you tell me which test are you referring to (There are too many that call the method I modified) ?
Should I remove remove the units tests I added and squash ?
This aims to reduce memory usage by reducing allocations when resolving dirty attribute indexes
Changes
I added the tests before making the changes to make sure my modifications didn't break the logic afterwards.
This optimizes memory usage by replacing ArrayList with BitSet for better memory allocation by:
Eliminating boxing overhead (Integer objects)
More efficient lookup with BitSet comapred to ArrayList "contains"
Converting to int[] only at the end and allocating exact size using bitSet.cardinality()
Related Issue
Fixes HHH-19850
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license
and can be relicensed under the terms of the LGPL v2.1 license in the future at the maintainers' discretion.
For more information on licensing, please check here.
https://hibernate.atlassian.net/browse/HHH-19850