@@ -110,19 +110,16 @@ public static String getPattern(String topic) {
110110 return "^" + Pattern .quote (get (topic ).getPartitionedTopicName ().toString ()) + "$" ;
111111 }
112112
113- private TopicName (String completeTopicName ) {
114- this (completeTopicName , true );
115- }
116-
117113 /**
118- * The constructor from a topic name string. You can leverage {@link TopicName#get(String)} to get benefits from
119- * the built-in cache mechanism.
114+ * The constructor from a topic name string. The difference from {@link TopicName#get(String)} is that the `get`
115+ * method can leverage the built-in cache mechanism, which can be slightly faster, but at the cost of higher JVM
116+ * memory usage that could lead to unnecessary GC, as well as potentially OOM in extreme cases.
117+ * You can benchmark `TopicName.get(topic)` and `new TopicName(topic)` to see the actual performance gap.
120118 *
121119 * @param completeTopicName the topic name
122- * @param initializeNamespaceName whether to initializing the internal {@link NamespaceName} field
123120 */
124121 @ SuppressFBWarnings ("DCN_NULLPOINTER_EXCEPTION" )
125- public TopicName (String completeTopicName , boolean initializeNamespaceName ) {
122+ public TopicName (String completeTopicName ) {
126123 try {
127124 // The topic name can be in two different forms, one is fully qualified topic name,
128125 // the other one is short topic name
@@ -179,10 +176,6 @@ public TopicName(String completeTopicName, boolean initializeNamespaceName) {
179176 this .domain = TopicDomain .getEnum (completeTopicName .substring (0 , index ));
180177 }
181178
182- if (initializeNamespaceName ) {
183- getNamespaceObject ();
184- }
185-
186179 if (StringUtils .isBlank (localName )) {
187180 throw new IllegalArgumentException (String .format ("Invalid topic name: %s. Topic local name must not"
188181 + " be blank." , completeTopicName ));
0 commit comments