-
Notifications
You must be signed in to change notification settings - Fork 579
8195614: FilteredList throws ArrayIndexOutOfBoundsException if created with 1 element #2163
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
Open
Maran23
wants to merge
1
commit into
openjdk:master
Choose a base branch
from
Maran23:8195614-FilteredList-throws-ArrayIndexOutOfBoundsException-if-created-with-1-element
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+21
−3
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
are you sure this is needed?
the tests in the two JBS tickets pass without it,
addRemove()invokes this method in ~L239 (then calls it again with size+1 in L273).update()calls it in ~L286, andpermutate()does not need it.perhaps
addRemove()can be further optimized so as not to callensureSize()twice?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.
update()andpermutate()do not call it anymore. I relocated them into one single location: Here.So functionality wise, it did not change.
We could probably remove it, as we will catch any grow on size in
addRemove(). But it might hurt performance.If we have a
FilteredListwith a size 1 and add 10_000 elements, we will callensureSizea lot of times, which will lead to a degraded performance.But since we call it once here, we will immediately grow to the worst case size - if nothing need to be filtered and MAY only grow it in
addRemove()when we temporarily have more elements due to processing the changes one by one.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 might be misunderstanding something.
ensureSize()L138 needed forpermutate()?addRemove()callsensureSize()twice (L138 and L237). can it call it only once?update()does not change the filtered size, right? why is it callingensureSize()in L138?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.
ensureSizeshould be a noop, since the size had to be increased at some point in the past to what we currently have and ensured the sizeensureSizecall. With that said, the second call inaddRemoveshould happen very rarely - probably only with small sizespermutation,- theensureSizeshould be a noop, since the size had to be increased at some point in the past to what we currently have and ensured the sizeThere 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.
So, while I agree that it's likely to be a no-op, my original comment did pointed out a possible optimization (not that it will give us megabytes or free space or 10% less CPU consumption).
So in cases 1) and 2) we could call
ensureSize()only when needed. It's up to you whether you want to pursue this further or leave as is.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 thought about it as well - but this is very hard to balance.
We reserve quite much space here. If we have 1000 elements, we reserve space for 1501 elements. That's huge. And we are in
FilteredList- so the normal usecase is probably with quite a few elements filtered out.But on the other hand growing in size just a few times is much better performance-wise vs. growing in size many more times. As I found out here already: #758