-
Notifications
You must be signed in to change notification settings - Fork 541
8283346: Optimize observable ArrayList creation in FXCollections #758
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
Conversation
|
👋 Welcome back mhanl! A progress list of the required criteria for merging this PR into |
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. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. 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. ➡️ To flag this PR as ready for integration with the above commit message, type |
|
/integrate |
|
/sponsor |
|
Going to push as commit b3eca1f.
Your commit was automatically rebased without conflicts. |
|
@kevinrushforth @Maran23 Pushed as commit b3eca1f. 💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored. |
This simple PR optimizes the observable
ArrayListcreation 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 theaddAllcall.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
gitCheckout this PR locally:
$ git fetch https://git.openjdk.org/jfx pull/758/head:pull/758$ git checkout pull/758Update a local copy of the PR:
$ git checkout pull/758$ git pull https://git.openjdk.org/jfx pull/758/headUsing Skara CLI tools
Checkout this PR locally:
$ git pr checkout 758View PR using the GUI difftool:
$ git pr show -t 758Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jfx/pull/758.diff