Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Please create CachedMemoryMeterStrategy that caches shallow sizes of classes #65

@daniel-rusu

Description

@daniel-rusu

I worked on a JVM memory measurement library that used reflection to analyze deep object graphs and found a very significant performance improvement by simply caching shallow sizes. I don't have references but I believe it was on the order of 10 times faster for some common scenarios.

The implementation would be quite trivial by creating a new CachedMemoryMeterStrategy class which contains:

  • a HashMap cache from class to shallow size
  • a regular MemoryMeterStrategy to be used as a fallback when measuring a new type of object that hasn't been encountered before

Scenarios where this is extremely beneficial:

  1. Collections and arrays usually store objects of the same type (or a small number of subtypes)
  2. Collections themselves can wrap every item ending up with many wrappers of the same type (such as Node in HashMap)
  3. Tree structures usually contain a very small number of types (eg. subtree & leaf nodes)

Even if an object graph contains no repeated classes, this allows us to re-use the same MemoryMeter instance to measure a large number of similar objects so that the cache from the first measurement speeds up the measurements of subsequent objects.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions