nicktelford opened a new pull request, #24189: URL: https://github.com/apache/kafka/pull/24189
`NamedCache#flush` and `NamedCache#clear` reset the `dirtyKeys` set with `LinkedHashSet#clear()`. `HashMap#clear()` sets every slot of its table to null, and the table never shrinks. Thus each reset costs as much as the largest number of dirty keys that the set ever held. After one flush with many distinct dirty keys, every later flush of that cache pays for the large table, for the life of the task. The table also stays on the heap, and `statestore.cache.max.bytes` does not count it. This change clears the set in place while its size matches the load, and replaces the set when a flush has fewer than a quarter of the peak keys since the last allocation. The flush also does this check when it has no dirty keys, so an idle store releases the table. A replacement on every flush is simpler, but at a high steady cardinality it allocates a large table on each flush, which caused many more GC cycles in the benchmark. The new `NamedCacheDirtyKeysFlushBenchmark` models the put/flush cycle. After a burst of 100k dirty keys, the mean cost of each cycle drops by 43–75%. In a steady workload, the cost stays within 2% of the current code. KAFKA-21469 contains the full results. 🤖 Generated with [Claude Code](https://claude.com/claude-code) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
