Skip to content
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

Autoboxing standard values or LRU cache #16

Open
ratcashdev opened this issue Jun 9, 2018 · 1 comment
Open

Autoboxing standard values or LRU cache #16

ratcashdev opened this issue Jun 9, 2018 · 1 comment

Comments

@ratcashdev
Copy link

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.

@ratcashdev
Copy link
Author

ratcashdev commented Jun 11, 2018

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant