velocity-tools icon indicating copy to clipboard operation
velocity-tools copied to clipboard

VELTOOLS-198

Open odoral opened this issue 3 years ago • 4 comments
trafficstars

odoral avatar Nov 08 '22 19:11 odoral

Now I wonder whether a TL would really be better than living without the cache. How big is the impact not using a cache?

michael-o avatar Nov 08 '22 19:11 michael-o

Thanks for identifying this issue.

On this page someone had a measurement of ~23ms for the format instantiation. This is a figure which is highly dependent on the measurement conditions but still, it means that in terms of number of cycles its order of magnitude is to be taken into consideration.

The thread-local paradigm is not optimal here since in a web context for instance, requests are rarely made by the same thread. I would rather use a pool, each thread taking a format instance from the pool and putting it back afterwards. Apache commons has plenty of ready-made pools for this use case.

arkanovicz avatar Nov 08 '22 20:11 arkanovicz

@arkanovicz While Commons Pool is very nice I use if for heavy objects as well, how do you want to expose its configuration, lifecycle, etc. to the client? As of now, the tools are more or less stateless.

michael-o avatar Nov 08 '22 21:11 michael-o

Now I wonder whether a TL would really be better than living without the cache. How big is the impact not using a cache?

To be honest, we found this issue in a migration from 2.0 to 3.1 so not sure about how much this cache can improve. In our case, we've custom tools where we initialise formatters and they are used during the tool scope so there is just one call to get them.

I just moved cache into TL to not change design.

odoral avatar Nov 08 '22 21:11 odoral