lucasbru opened a new pull request, #12903: URL: https://github.com/apache/kafka/pull/12903
Optimization of `ThreadCache`. The original implementation showed significant slow-down when many caches were registered. `sizeBytes` was called at least once, and potentially many times in every `put` and was linear in the number of caches (= number of state stores, so typically proportional to number of tasks). That means, with every additional task, every put gets a little slower. This was confirmed experimentally. In this change, we modify the implementation of `ThreadCache` to keep track of the total size in bytes. To be independent of the concrete implementation of the underlying cache, we update the size by subtracting the old and adding the new size of the cache before and after every modifying operation. For this we acquire the object monitor of the cache, but since all modifying operations on the caches are synchronized already, this should not cause extra overhead. This change also fixes a `ConcurrentModificationException` that could be thrown in a race between `sizeBytes` and `getOrCreate`. The new implementation of `syzeBytes` is tested by existing unit tests. ### Committer Checklist (excluded from commit message) - [x] Verify design and implementation - [x] Verify test coverage and CI build status - [x] Verify documentation (including upgrade notes) -- 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: jira-unsubscr...@kafka.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org