You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As Money is an immutable class, I was wondering if it wouldn't be good to add autoboxing of some frequently used values (0, 1, 2 ..) and/or some decimals (0.1,0.2 etc)
Or, autobox some integer values and use an LRU cache for the most frequently used decimals.
The text was updated successfully, but these errors were encountered:
Apparently, based on some quick tests, retrieving values from the LRUCache (LinkedHashMap) and maintaining the cache is approximately twice as slow as creating new instances. This may be even worse for concurret access (synchronized write or ConcurrentLinkedHashMap)
This assumes that cacheSize << cardinality_of_poossible_values.
Nevertheless this may still make sense in a memory-constrained environment, where the occurrence of a single value is >> 1, Here retrieving and re-using a single instance from the cache could be advantageous to avoid GC thrashing, in spite of the performance handicap.
As Money is an immutable class, I was wondering if it wouldn't be good to add autoboxing of some frequently used values (0, 1, 2 ..) and/or some decimals (0.1,0.2 etc)
Or, autobox some integer values and use an LRU cache for the most frequently used decimals.
The text was updated successfully, but these errors were encountered: