Flyweight support of key re-used objects #3940
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I wanted to see if flyweight objects could be used for two very commonly created "cache key" objects, namely
CacheKey
andFieldCoordinates
This results in WAY less objects being allocated when they are used over and over with the same values. So this is a nett saving in memory in a a called system that is loading the same logical objects over and over. And this is likely to always be the case.
HOWEVER the thing happening here in terms of speed is
And the answer to that is that new Java objects are 361% faster than map lookups.
So this becomes a trade off between objects being allocated and cpu throughput
And its not worth taking - we should not merge this PR
However I wanted to create the PR to show my working
Note here how its much slower in cpu terms but much more efficient in memory terms with a lot less GC happening