lhotari commented on code in PR #25367:
URL: https://github.com/apache/pulsar/pull/25367#discussion_r3101546500
##########
pulsar-common/src/main/java/org/apache/pulsar/common/naming/TopicName.java:
##########
@@ -77,12 +77,32 @@ public static TopicName get(String domain, String tenant,
String namespace, Stri
return TopicName.get(name);
}
+ /**
+ * Get or create a TopicName from the cache.
+ *
+ * <p>Optimization over {@code computeIfAbsent}: avoids holding the
ConcurrentHashMap bin-lock
+ * while constructing a new TopicName object. The construction (string
splitting / parsing) is
+ * pure CPU work and can be done outside the lock. In the typical
steady-state (cache hit) this
+ * method does a single volatile read via {@code get()} and returns
immediately with no
+ * synchronization overhead.
+ *
+ * <p>In the cache-miss case, two threads racing on the same key may both
construct a
+ * {@code TopicName} instance, but only one wins the {@code putIfAbsent}
and the loser's
+ * instance is simply discarded. This is safe because {@code TopicName} is
immutable and
+ * construction is cheap compared to the lock-contention / context-switch
cost of
+ * {@code computeIfAbsent}.
Review Comment:
these details could be in code comments since the public API user shouldn't
need to know about the implementation details.
--
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]