merlimat commented on code in PR #24463:
URL: https://github.com/apache/pulsar/pull/24463#discussion_r2224856707


##########
pulsar-common/src/main/java/org/apache/pulsar/common/naming/TopicName.java:
##########
@@ -111,64 +110,70 @@ public static String getPattern(String topic) {
         return "^" + 
Pattern.quote(get(topic).getPartitionedTopicName().toString()) + "$";
     }
 
+    /**
+     * The constructor from a topic name string. The difference from {@link 
TopicName#get(String)} is that the `get`
+     * method can leverage the built-in cache mechanism, which can be slightly 
faster, but at the cost of higher JVM
+     * memory usage that could lead to unnecessary GC, as well as potentially 
OOM in extreme cases.
+     * You can benchmark `TopicName.get(topic)` and `new TopicName(topic)` to 
see the actual performance gap.
+     *
+     * @param completeTopicName the topic name
+     */
     @SuppressFBWarnings("DCN_NULLPOINTER_EXCEPTION")
-    private TopicName(String completeTopicName) {
+    public TopicName(String completeTopicName) {

Review Comment:
   If it's to be used in the benchmark, let's leave the constructor package 
protected.



##########
microbench/src/main/java/org/apache/pulsar/broker/qos/TopicNameBenchmark.java:
##########
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pulsar.broker.qos;
+
+import java.util.concurrent.TimeUnit;
+import org.apache.pulsar.common.naming.TopicName;
+import org.openjdk.jmh.annotations.Benchmark;
+import org.openjdk.jmh.annotations.BenchmarkMode;
+import org.openjdk.jmh.annotations.Fork;
+import org.openjdk.jmh.annotations.Measurement;
+import org.openjdk.jmh.annotations.Mode;
+import org.openjdk.jmh.annotations.OutputTimeUnit;
+import org.openjdk.jmh.annotations.Scope;
+import org.openjdk.jmh.annotations.State;
+import org.openjdk.jmh.annotations.Threads;
+import org.openjdk.jmh.annotations.Warmup;
+import org.openjdk.jmh.infra.Blackhole;
+
+@Fork(1)
+@BenchmarkMode(Mode.Throughput)
+@OutputTimeUnit(TimeUnit.SECONDS)
+@State(Scope.Thread)
+public class TopicNameBenchmark {
+
+    private static final String[] topicBases = {"test",
+            "tenant/ns/test",
+            "persistent://another-tenant/another-ns/test"
+    };
+
+    @Threads(1)
+    @Benchmark
+    @Warmup(time = 5, iterations = 1)
+    @Measurement(time = 5, iterations = 1)
+    public void testReadFromCache(Blackhole blackhole) {

Review Comment:
   Since this contains loops, it's better to add annotation to have more 
understandable number: `@OperationsPerInvocation(10_000 * 3)`
   
   Also, `@OutputTimeUnit(TimeUnit.MICROSECONDS)` might be good



##########
pulsar-common/src/main/java/org/apache/pulsar/common/naming/TopicName.java:
##########
@@ -211,6 +208,16 @@ public String getNamespace() {
      */
     @Override
     public NamespaceName getNamespaceObject() {
+        if (namespaceName != null) {
+            return namespaceName;

Review Comment:
   We shouldn't need to have `namespaceName` volatile, we can just check it 
again in the synchronized block.



-- 
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: commits-unsubscr...@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to