arunpandianp commented on code in PR #33580:
URL: https://github.com/apache/beam/pull/33580#discussion_r1915840487


##########
runners/google-cloud-dataflow-java/worker/src/main/java/org/apache/beam/runners/dataflow/worker/WindmillTimerInternals.java:
##########
@@ -406,36 +404,27 @@ private static boolean useNewTimerTagEncoding(TimerData 
timerData) {
    */
   public static ByteString timerTag(WindmillNamespacePrefix prefix, TimerData 
timerData) {
     String tagString;
-    ExposedByteArrayOutputStream out = new ExposedByteArrayOutputStream();
-    try {
-      if (useNewTimerTagEncoding(timerData)) {
-        tagString =
-            new StringBuilder()
-                .append(prefix.byteString().toStringUtf8()) // this never ends 
with a slash
-                .append(
-                    timerData.getNamespace().stringKey()) // this must begin 
and end with a slash
-                .append('+')
-                .append(timerData.getTimerId()) // this is arbitrary; 
currently unescaped
-                .append('+')
-                .append(timerData.getTimerFamilyId())
-                .toString();
-        out.write(tagString.getBytes(StandardCharsets.UTF_8));
-      } else {
-        // Timers without timerFamily would have timerFamily would be an empty 
string
-        tagString =
-            new StringBuilder()
-                .append(prefix.byteString().toStringUtf8()) // this never ends 
with a slash
-                .append(
-                    timerData.getNamespace().stringKey()) // this must begin 
and end with a slash
-                .append('+')
-                .append(timerData.getTimerId()) // this is arbitrary; 
currently unescaped
-                .toString();
-        out.write(tagString.getBytes(StandardCharsets.UTF_8));
-      }
-      return ByteString.readFrom(new 
ExposedByteArrayInputStream(out.toByteArray()));
-    } catch (IOException e) {
-      throw new RuntimeException(e);
+    if (useNewTimerTagEncoding(timerData)) {
+      tagString =
+          new StringBuilder()
+              .append(prefix.byteString().toStringUtf8()) // this never ends 
with a slash
+              .append(timerData.getNamespace().stringKey()) // this must begin 
and end with a slash
+              .append('+')
+              .append(timerData.getTimerId()) // this is arbitrary; currently 
unescaped
+              .append('+')
+              .append(timerData.getTimerFamilyId())
+              .toString();
+    } else {
+      // Timers without timerFamily would have timerFamily would be an empty 
string
+      tagString =
+          new StringBuilder()
+              .append(prefix.byteString().toStringUtf8()) // this never ends 
with a slash
+              .append(timerData.getNamespace().stringKey()) // this must begin 
and end with a slash
+              .append('+')
+              .append(timerData.getTimerId()) // this is arbitrary; currently 
unescaped
+              .toString();
     }
+    return ByteString.copyFromUtf8(tagString);

Review Comment:
   I think so, `ByteString.copyFromUtf8`  uses `LiteralByteString` internally 
and doesn't create a copy of `byte[]` from `tagString.getBytes`.



-- 
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]

Reply via email to