sjvanrossum opened a new pull request, #40770: URL: https://github.com/apache/beam/pull/40770
There were previously no microbenchmarks measuring `Row` to/from JSON serialization and deserialization throughput across flat and nested/composite schemas. Adds `RowJsonBenchmark` covering both `String` and `byte[]` pathways (`RowJson` and `JsonUtils`). `JsonUtils` and `JsonPayloadSerializerProvider` previously decoded `byte[]` payloads into a `new String(..., UTF_8)` before parsing and serialized `Row`s to a `String` before calling `.getBytes(UTF_8)`. Adds direct `byte[]` helpers on `RowJsonUtils` (`jsonBytesToRow` / `rowToJsonBytes`) using Jackson's `ObjectReader.readValue(byte[])` and `ObjectWriter.writeValueAsBytes(Object)` to read and write UTF-8 bytes directly. `RowJsonDeserializer` and `RowJsonSerializer` allocated an `AutoValue` `FieldValue` wrapper on every field, used `Stream` pipelines (`IntStream`, `StreamSupport`) to iterate over arrays/rows, and used `SequentialRead` sequential lists for array values. Replaces `Stream` pipelines and `FieldValue` wrappers with direct loops, `ArrayList` sizing, and `Row.withSchema(schema).attachValues(...)`. `RowJsonDeserializer` previously called `jsonParser.readValueAsTree()` to materialize an entire Jackson `ObjectNode` / `ArrayNode` AST in memory before extracting `Row` fields. Streams tokens directly from `JsonParser` in a single pass with `ParserExtractor`s, caches the bound `ObjectReader` / `ObjectWriter` in `JsonUtils`, and avoids intermediate tree allocations altogether. | Benchmark | Current (ops/us) | Proposed (ops/us) | Speedup | | :--- | :---: | :---: | :---: | | `deserializeComplexRowBytes` | 0.298 ± 0.006 | **0.415 ± 0.015** | **+39.3% (1.39x)** | | `deserializeComplexRowString` | 0.285 ± 0.021 | **0.413 ± 0.009** | **+44.9% (1.45x)** | | `deserializeFlatRowString` | 0.471 ± 0.014 | **0.531 ± 0.024** | **+12.7% (1.13x)** | | `serializeComplexRowBytes` | 2.085 ± 0.115 | **2.226 ± 0.119** | **+6.8% (1.07x)** | | `serializeComplexRowString` | 2.068 ± 0.101 | **2.106 ± 0.068** | **+1.8% (1.02x)** | > [!NOTE] > This PR stacks on top of #40769 -- 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]
