jbellis / jamm

Java Agent for Memory Measurements
Apache License 2.0
684 stars 125 forks source link

Allow users to improve MemoryMeter performance for specific use cases #54

Closed blerer closed 1 year ago

blerer commented 1 year ago

By default Jamm should provided correct measurements while being as simple as possible to use. Nevertheless for some usecases people might wish to make some trade off to get better faster measurements out of Jamm.

There are different areas on which user could play to get better performance:

Eliminating the cost of reflection

The cost of reflection could be eliminated by providing a way for classes to add their children objects directly to the stack instead of having to rely on reflection. The drawback of this approach is that it push the responsibility to the user to ensure that all children are taken into account.

Caching measurement

Jamm should allow users to define a simple caching strategy for measurements

Using the more efficient measurements even if the belongs to different strategies

The INSTRUMENTATION strategy outperform other strategies for non array measurements but other strategies are more performant for array measurements. As array measurements do not suffer from correctness issue we could create a new strategy that use Instrumentation to measure non array objects and the SPEC approach for array objects

blerer commented 1 year ago

After looking into it, we decided to stay away from caching as it has some impact on memory that are difficult to plan for.

blerer commented 1 year ago

The final changes are: