HCL-TECH-SOFTWARE / domino-jnx

Modern Domino Java API based on JNA access to Domino's C API
https://opensource.hcltechsw.com/domino-jnx/
Apache License 2.0
14 stars 3 forks source link

cache formula and sizeof #363

Closed sunpei1 closed 1 year ago

sunpei1 commented 1 year ago

When testing Keep /lists endpoint, we found some hotspot area in jnx code: image image

This PR use cache to avoid these hotspots. Together with the previous findRequiredService fix, all these changes can double the /lists endpoint's throughput.

klehmann commented 1 year ago

Great find! Although I am surprised that getSelectionFormula() is called more than once in Keep, it's a good idea to cache the value. @jesse-gallagher what do you think? Is caching the memory structure size safe or are the any cases where this value changes dynamically (e.g. for the db design)?

jesse-gallagher commented 1 year ago

I think it should be fine - while an individual instance may have a different size, that method only deals with the Class anyway.

However, I think it'd be good to replace the HashMap with a ConcurrentHashMap and use the computeIfAbsent method to calculate if necessary. That will be both more explicit in wording and also thread-safe. That'd be the same pattern as in my variant JNXServiceFinder.

sunpei1 commented 1 year ago

@jesse-gallagher good suggestion, I'll replace it.

sunpei1 commented 1 year ago

@jesse-gallagher updated with concurrentHashMap, please review:)

sunpei1 commented 1 year ago

Here's the profiling results with this patch, the formula branch disappear from the fireflame graph:

image

sunpei1 commented 1 year ago

@jesse-gallagher is there any more comments on this PR?

jesse-gallagher commented 1 year ago

Most likely not - I'm out this week and last, though, so I expect that I'll merge it in next week.