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
Move instance field to static #714
base: master
Are you sure you want to change the base?
Move instance field to static #714
Conversation
Looks like a good catch. |
@DanielThomas Could you also do: RoaringBitmap/RoaringBitmap/src/main/java/org/roaringbitmap/buffer/MappeableBitmapContainer.java Line 55 in dda04be
|
@lemire I removed some duplication and switched in some size constants. Do you mind the cross-cutting package imports? |
@@ -2234,7 +2236,7 @@ private void smartAppendExclusive(char[] vl, char start, char length) { | |||
// convert to bitmap *if needed* (useful if you know it can't be an array) | |||
private MappeableContainer toBitmapIfNeeded() { | |||
int sizeAsRunContainer = MappeableRunContainer.serializedSizeInBytes(this.nbrruns); | |||
int sizeAsBitmapContainer = MappeableBitmapContainer.serializedSizeInBytes(0); | |||
int sizeAsBitmapContainer = serializedSizeInBytes(0); |
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.
Oops, let me fix this.
52ad699
to
8eb63c1
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.
I guess nobody ever spotted this because bitmap containers contain an 8KiB array, so if you have enough of them for this slip up to show up noticeably, you would be distracted by hundreds of MiBs or even GiBs of long[]
in the heap dump, but this is a great catch.
YourKit's duplicate object inspection :) |
Interestingly, this won't always amount to a footprint optimisation, because the stray field will usually fit into alignment shadow anyway (1.0.5) System.err.println(ClassLayout.parseClass(BitmapContainer.class).toPrintable());
but will save 8 bytes per
|
@DanielThomas Can you check the CI logs? I see...
|
@DanielThomas This PR still does not build...
|
Sorry @lemire, let me get that fixed. |
8eb63c1
to
f75455d
Compare
Based on your comments on the other PR about code duplication being a thing for the project, I've rolled back any other changes and restricted this to making the field in |
Note that it is not that we encourage code duplication; it is merely that, historically, we have accepted it in this library. I do not discourage you from removing unnecessary code duplication. However, I prefer to be prudent with code refactoring that merely reduces code duplication because we can introduce new bugs by mistake. |
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 try to keep in sync BitmapContainer.java and MappeableBitmapContainer.java. Could you apply your changes to MappeableBitmapContainer.java.
See...
RoaringBitmap/RoaringBitmap/src/main/java/org/roaringbitmap/buffer/MappeableBitmapContainer.java
Line 55 in 5235aa6
private final int MAXRUNS = (getArraySizeInBytes() - 2) / 4; |
SUMMARY
This adds an additional unnecessary reference to every
BitmapContainer
.Automated Checks
./gradlew test
and made sure that my PR does not break any unit test../gradlew checkstyleMain
or the equivalent and corrected the formatting warnings reported.