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
8283346: Optimize observable ArrayList creation in FXCollections #758
8283346: Optimize observable ArrayList creation in FXCollections #758
Conversation
|
Webrevs
|
This PR appears to have two internal behavior changes.
ModifiableObservableListBase.java @Override
public void add(int index, E element) {
doAdd(index, element);
beginChange();
nextAdd(index, index + 1);
++modCount;
endChange();
}
ObservableListWrapper.java @Override
protected void doAdd (int index, E element) {
if (elementObserver! = null)
elementObserver.attachListener (element);
backingList.add (index, element);
} ObservableListWrapper.java public ObservableListWrapper(List<E> list) {
backingList = list;
elementObserver = null;
} We will need to make sure that the current unit tests cover B's changes. |
The following pieces of code should be identical: var list = FXCollections.observableArrayList();
list.addAll(source); var list = FXCollections.observableList(new ArrayList<>(source)); Any observable difference in behavior would be unspecified. When it comes to |
This is fine as the mod count is only there to detect concurrent modifications. |
/reviewers 2 |
@kevinrushforth |
modules/javafx.base/src/main/java/javafx/collections/FXCollections.java
Outdated
Show resolved
Hide resolved
…d caused by adding items to the observable list
modules/javafx.base/src/main/java/javafx/collections/FXCollections.java
Outdated
Show resolved
Hide resolved
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.
Looks good. I left a few small comments.
I ran some benchmarks and I can reproduce the performance improvement both in the array (varargs) and the collection variants of the method.
modules/javafx.base/src/test/java/test/javafx/collections/FXCollectionsTest.java
Outdated
Show resolved
Hide resolved
modules/javafx.base/src/test/java/test/javafx/collections/FXCollectionsTest.java
Outdated
Show resolved
Hide resolved
modules/javafx.base/src/main/java/javafx/collections/FXCollections.java
Outdated
Show resolved
Hide resolved
Thanks for the review and verifying the improvement. |
@Maran23 This change now passes all automated pre-integration checks. After integration, the commit message for the final commit will be:
You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been 46 new commits pushed to the
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details. As you do not have Committer status in this project an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@nlisker, @kevinrushforth) but any other Committer may sponsor as well.
|
/integrate |
/sponsor |
Going to push as commit b3eca1f.
Your commit was automatically rebased without conflicts. |
@kevinrushforth @Maran23 Pushed as commit b3eca1f. |
This simple PR optimizes the observable
ArrayList
creation by using the ArrayList constructor/array size so that the underlying array will be initialized at the correct size which will speed up the creation as the array does not need to grow as a result of theaddAll
call.I also added tests which will succeed before and after to verify that nothing got broken by this change.
Also I made a benchmark test. Results:
Edit: I also made a synthetic benchmark by measuring the same code below 100 times with
System.nanoTime
.ListBenchmark OLD (avg): 21-23ms
ListBenchmark NEW (avg): 2 ms
Benchmark code
Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jfx pull/758/head:pull/758
$ git checkout pull/758
Update a local copy of the PR:
$ git checkout pull/758
$ git pull https://git.openjdk.org/jfx pull/758/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 758
View PR using the GUI difftool:
$ git pr show -t 758
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jfx/pull/758.diff