-
Notifications
You must be signed in to change notification settings - Fork 168
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
Reduce memory overhead caused by default collection sizes #4562
Conversation
f45378a
to
8425a19
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 5 of 5 files at r1.
Reviewable status: all discussions resolved, 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.
Reviewed 4 of 5 files at r1.
Reviewable status: 2 unresolved discussions, 1 of 1 LGTMs obtained
flow-server/src/main/java/com/vaadin/flow/component/ComponentEventBus.java, line 155 at r1 (raw file):
} componentEventData.computeIfAbsent(eventType, t -> new ArrayList<>())
This ArrayList
could also have initial capacity.
Most commonly it will contain only one item, since it's rare to add multiple listeners for the same event type.
flow-server/src/main/java/com/vaadin/flow/internal/nodefeature/ElementListenerMap.java, line 356 at r1 (raw file):
listeners.containsKey(eventType)
This returns always true
, (because of the above listenerList != null
check), so what's the point of having it in here?
assert
would make more sense if you want to include this check anyway.
flow-server/src/main/java/com/vaadin/flow/internal/nodefeature/ElementPropertyMap.java, line 151 at r1 (raw file):
propertyListeners.add(listener); return () -> propertyListeners.remove(listener);
I guess removal could also be optimized like in ElementListenerMap
?
But that's not as common case, with not as big benefits, so not blocking.
There are various collections that are usually not used at all or with only a small number of items. Allocating the default sizes for such collections wastes quite some memory: HashSet and HashMap allocate for 16 items by default, ArrayList for 10 items and IdentityHashMap for 32. Reduces BasicElementView memory use from 429706 to 419682 bytes and the memory use in BeverageBuddy with an edit dialog open from 262257 to 251569 bytes.
8425a19
to
1be700a
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: 2 unresolved discussions, 0 of 1 LGTMs obtained, and 1 stale
flow-server/src/main/java/com/vaadin/flow/component/ComponentEventBus.java, line 155 at r1 (raw file):
Previously, pekam (Pekka Maanpää) wrote…
This
ArrayList
could also have initial capacity.
Most commonly it will contain only one item, since it's rare to add multiple listeners for the same event type.
Done.
flow-server/src/main/java/com/vaadin/flow/internal/nodefeature/ElementListenerMap.java, line 356 at r1 (raw file):
Previously, pekam (Pekka Maanpää) wrote…
listeners.containsKey(eventType)
This returns always
true
, (because of the abovelistenerList != null
check), so what's the point of having it in here?
assert
would make more sense if you want to include this check anyway.
Done.
SonarQube analysis reported 5 issues Note: The following issues were found on lines that were not modified in the pull request. Because these issues can't be reported as line comments, they are summarized here:
|
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 2 files at r2.
Reviewable status: all discussions resolved, 0 of 1 LGTMs obtained, and 2 stale
There are various collections that are usually not used at all or with
only a small number of items. Allocating the default sizes for such
collections wastes quite some memory: HashSet and HashMap allocate for
16 items by default, ArrayList for 10 items and IdentityHashMap for 32.
Reduces BasicElementView memory use from 429706 to 419682 bytes and the
memory use in BeverageBuddy with an edit dialog open from 262257 to
251569 bytes.
This change is