Copilot commented on code in PR #17485:
URL: https://github.com/apache/pinot/pull/17485#discussion_r2678731264


##########
pinot-spi/src/main/java/org/apache/pinot/spi/utils/JsonUtils.java:
##########
@@ -247,6 +247,20 @@ public static Map<String, Object> jsonNodeToMap(JsonNode 
jsonNode)
     return DEFAULT_READER.forType(MAP_TYPE_REFERENCE).readValue(jsonNode);
   }
 
+  /**
+   * Parses JSON bytes directly to a Map, avoiding the intermediate JsonNode 
representation.
+   * This is more efficient than calling bytesToJsonNode followed by 
jsonNodeToMap.
+   */
+  public static Map<String, Object> bytesToMap(byte[] jsonBytes)
+      throws IOException {
+    return DEFAULT_READER.forType(MAP_TYPE_REFERENCE).readValue(jsonBytes);
+  }
+
+  public static Map<String, Object> bytesToMap(byte[] jsonBytes, int offset, 
int length)
+      throws IOException {
+    return DEFAULT_READER.forType(MAP_TYPE_REFERENCE).readValue(jsonBytes, 
offset, offset + length);

Review Comment:
   The third parameter should be `length`, not `offset + length`. The 
`readValue(byte[] src, int offset, int len)` method expects the length of data 
to read, not the end offset. This will cause incorrect parsing when offset is 
non-zero.
   ```suggestion
       return DEFAULT_READER.forType(MAP_TYPE_REFERENCE).readValue(jsonBytes, 
offset, length);
   ```



##########
pinot-perf/src/main/java/org/apache/pinot/perf/BenchmarkJsonParsing.java:
##########
@@ -0,0 +1,282 @@
+/**
+ * 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.pinot.perf;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Random;
+import java.util.concurrent.TimeUnit;
+import org.apache.pinot.spi.utils.JsonUtils;
+import org.openjdk.jmh.annotations.Benchmark;
+import org.openjdk.jmh.annotations.BenchmarkMode;
+import org.openjdk.jmh.annotations.Fork;
+import org.openjdk.jmh.annotations.Level;
+import org.openjdk.jmh.annotations.Measurement;
+import org.openjdk.jmh.annotations.Mode;
+import org.openjdk.jmh.annotations.OutputTimeUnit;
+import org.openjdk.jmh.annotations.Param;
+import org.openjdk.jmh.annotations.Scope;
+import org.openjdk.jmh.annotations.Setup;
+import org.openjdk.jmh.annotations.State;
+import org.openjdk.jmh.annotations.Warmup;
+import org.openjdk.jmh.infra.Blackhole;
+import org.openjdk.jmh.runner.Runner;
+import org.openjdk.jmh.runner.options.ChainedOptionsBuilder;
+import org.openjdk.jmh.runner.options.OptionsBuilder;
+
+
+/**
+ * Benchmark to compare JSON parsing performance:
+ * - Old approach: bytesToJsonNode() + jsonNodeToMap() (two-step parsing)
+ * - New approach: bytesToMap() (single-step parsing)
+ *
+ * This benchmark simulates the JSON decoding path in 
RealtimeSegmentDataManager.consumeLoop()
+ * where JSONMessageDecoder.decode() is called for each message from the 
stream.
+ *
+ * Run with: mvn exec:exec -Dexec.executable="java" -Dexec.args="-cp 
%classpath org.apache.pinot.perf
+ * .BenchmarkJsonParsing"

Review Comment:
   Line break in the middle of the class name makes this command 
non-functional. The command should be on a single line or properly formatted 
with line continuation.
   ```suggestion
    * Run with: mvn exec:exec -Dexec.executable="java" -Dexec.args="-cp 
%classpath org.apache.pinot.perf.BenchmarkJsonParsing"
   ```



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

Reply via email to