On Tue, 25 Feb 2020 00:45:06 GMT, Kevin Rushforth <k...@openjdk.org> wrote:

>> modules/javafx.base/src/main/java/com/sun/javafx/binding/ExpressionHelper.java
>>  line 194:
>> 
>>> 193:         private Map<InvalidationListener, Integer> 
>>> invalidationListeners = new LinkedHashMap<>();
>>> 194:         private Map<ChangeListener<? super T>, Integer> 
>>> changeListeners = new LinkedHashMap<>();
>>> 195:         private T currentValue;
>> 
>> Two comments on this:
>> 
>> 1. The old implementation initialized these lazily, so we might want to 
>> preserve that behavior. I think it is reasonable since in most cases an 
>> observable won't have both types of listeners attached to it.
>> 2. Since we're dealing wither performance optimizations here, we should 
>> think about what the `initialCapcity` and `loadFactor` of these maps should 
>> be, as it can greatly increase performance when dealing with a large amount 
>> of entries.
> 
> Adding to this, we need to ensure that the simple case of a few listeners 
> doesn't suffer memory bloat. It may make sense to initially allocate a Map 
> with a small capacity and load factor, and then reallocate it if someone adds 
> more than a certain number of listeners.

Agree with the lazy initialisation and the initial setting of capacity and load 
factor to reduce memory footprint unless it's needed.

-------------

PR: https://git.openjdk.java.net/jfx/pull/108

Reply via email to