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
Minimize features array size #4584
Conversation
ee21040
to
b57d46c
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.
Reviewed 2 of 3 files at r1, 1 of 1 files at r2.
Reviewable status: 4 unresolved discussions, 0 of 1 LGTMs obtained
flow-server/src/main/java/com/vaadin/flow/internal/StateNode.java, line 360 at r2 (raw file):
public <T extends NodeFeature> T getFeature(Class<T> featureType) { int featureIndex = getFeatureIndex(featureType);
Please add a comment in the code for the future generation of maintainers to understand what is this about (and why a simple array is not used like in previous reviews). I know the comment in PR explains it already, but it is more straightforward to have it on the code as well.
flow-server/src/main/java/com/vaadin/flow/internal/StateNode.java, line 371 at r2 (raw file):
features = new NodeFeature[featureIndex + 1]; } else if (features instanceof NodeFeature) { features = new NodeFeature[] { (NodeFeature) features };
Here you could create the array already with the correct size (to avoid creating it and discarding it a few lines below).
flow-server/src/main/java/com/vaadin/flow/internal/nodefeature/NodeFeatureRegistry.java, line 120 at r2 (raw file):
/* Only used for the root node */
Could put this comment over her as well, to be consistent with the test.
flow-server/src/test/java/com/vaadin/flow/internal/nodefeature/NodeFeatureTest.java, line 165 at r2 (raw file):
ReconnectDialogConfigurationMap.class); Assert.assertEquals(priorityOrder.size(), expectedOrder.size());
The order here is reversed. It should be assertEquals(expectedOrder.size(), priorityOrder.size())
.
Order index mapping of feature types according to how often they are actually used (based on actual use frequencies in Beverage Buddy and Bakery). This allows allocating a smaller features array for each state node to only hold the features that are actually instantiated. The case with only one used feature is further optimized to directly store the feature instance instead of using a one-item array. Reduces BasicElementView memory use from 149909 to 136045 bytes and the memory use in BeverageBuddy with an edit dialog open from 151733 to 146061 bytes.
b57d46c
to
482e9e2
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.
Reviewable status: 4 unresolved discussions, 0 of 1 LGTMs obtained
flow-server/src/main/java/com/vaadin/flow/internal/StateNode.java, line 360 at r2 (raw file):
Previously, gilberto-torrezan (Gilberto Torrezan) wrote…
Please add a comment in the code for the future generation of maintainers to understand what is this about (and why a simple array is not used like in previous reviews). I know the comment in PR explains it already, but it is more straightforward to have it on the code as well.
Done.
flow-server/src/main/java/com/vaadin/flow/internal/StateNode.java, line 371 at r2 (raw file):
Previously, gilberto-torrezan (Gilberto Torrezan) wrote…
Here you could create the array already with the correct size (to avoid creating it and discarding it a few lines below).
Done.
flow-server/src/main/java/com/vaadin/flow/internal/nodefeature/NodeFeatureRegistry.java, line 120 at r2 (raw file):
Previously, gilberto-torrezan (Gilberto Torrezan) wrote…
/* Only used for the root node */
Could put this comment over her as well, to be consistent with the test.
Done.
flow-server/src/test/java/com/vaadin/flow/internal/nodefeature/NodeFeatureTest.java, line 165 at r2 (raw file):
Previously, gilberto-torrezan (Gilberto Torrezan) wrote…
The order here is reversed. It should be
assertEquals(expectedOrder.size(), priorityOrder.size())
.
Done.
@@ -349,10 +358,46 @@ protected void setTree(StateTree tree) { | |||
public <T extends NodeFeature> T getFeature(Class<T> featureType) { |
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.
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.
Reviewed 3 of 3 files at r3.
Reviewable status: 1 unresolved discussion, 0 of 1 LGTMs obtained, and 1 stale
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.
Dismissed @vaadin-bot from a discussion.
Reviewable status: complete! all discussions resolved, 1 of 1 LGTMs obtained
Order index mapping of feature types according to how often they are
actually used (based on actual use frequencies in Beverage Buddy and
Bakery). This allows allocating a smaller features array for each state
node to only hold the features that are actually instantiated.
The case with only one used feature is further optimized to directly
store the feature instance instead of using a one-item array.
Reduces BasicElementView memory use from 149909 to 136045 bytes and the
memory use in BeverageBuddy with an edit dialog open from 151733 to
146061 bytes.
This change is