He-Pin opened a new issue, #3132: URL: https://github.com/apache/pekko/issues/3132
### Motivation In `DistributedPubSubMediator`, topic name encoding (`URLEncoder.encode`) and key construction (`mkKey(self.path / encName(topic))`) are performed on every Publish, Subscribe, Unsubscribe, and CountSubscribers message. For high-throughput pub/sub workloads with a limited set of recurring topic names, this creates unnecessary allocations and CPU overhead on the hot path. The topic names and their encoded forms are typically stable — the same topics are published to and subscribed from repeatedly. Caching the encoded names and constructed keys avoids redundant string allocations and URL encoding operations. ### Proposed Enhancement Introduce a lightweight cache (e.g., a `HashMap` or similar structure) that stores: 1. The URL-encoded form of topic names 2. The fully constructed routing keys The cache should be: - Bounded to prevent unbounded memory growth if topic names are dynamic - Invalidated when topics are removed/pruned - Thread-safe within the mediator actor's single-threaded context (no locking needed since the mediator is an actor) ### Impact - Reduced allocations on the pub/sub hot path - Lower GC pressure in high-throughput scenarios - No API changes — purely internal optimization - The trade-off is a small amount of additional memory for the cache ### References This optimization was implemented in the Akka.NET project: https://github.com/akkadotnet/akka.net/issues/7642 -- 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] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
