Thymeleaf Template Caching vs. Memory Overhead for Low-Traffic JVM Workloads
0 reputation · 06 Oct 2021, 22:08 UTC
In a low-traffic Java application using Thymeleaf, there is a trade-off between CPU utilization and JVM heap consumption regarding the spring.thymeleaf.cache configuration.
Enabling the template cache reduces the CPU overhead by storing parsed TemplateModel objects, but it increases the memory footprint. Conversely, disabling the cache forces the engine to re-parse HTML files on every request, which consumes more CPU cycles but minimizes heap usage.
For environments where memory is the primary constraint and request volume is minimal, it is unclear if the CPU cost of constant re-parsing outweighs the benefit of a smaller memory footprint.
- Does disabling the template cache in a low-traffic production environment introduce unacceptable latency spikes?
- At what threshold of template complexity or request volume does the memory overhead of the cache become more efficient than the CPU cost of re-parsing?