github-actions[bot] commented on code in PR #41761:
URL: https://github.com/apache/beam/pull/41761#discussion_r4736312381
##########
sdks/java/extensions/avro/src/main/java/org/apache/beam/sdk/extensions/avro/schemas/utils/AvroUtils.java:
##########
@@ -1298,8 +1334,20 @@ private static org.apache.avro.Schema getFieldSchema(
return value;
}
- if (NUMERIC_CONVERTERS.containsKey(typeWithNullability.type)) {
- return NUMERIC_CONVERTERS.get(typeWithNullability.type).apply((Number)
value);
+ org.apache.avro.Schema unwrapped = typeWithNullability.type;
+ if (unwrapped.getLogicalType() == null &&
unwrapped.getObjectProps().isEmpty()) {
Review Comment:
**🟠High**: `org.apache.avro.JsonProperties.getObjectProps()` allocates and
populates a new `LinkedHashMap` (plus a `Collections.unmodifiableMap` wrapper
and entry-set iterator in Avro 1.9+) on every call. Because this check runs
before `switch (unwrapped.getType())`, it will allocate a map on every non-null
field of every row (including `STRING`, `BYTES`, `RECORD`, `ARRAY`, etc.),
negating the savings from removing `NUMERIC_CONVERTERS`.
To avoid allocating while still excluding logical types without a registered
`LogicalType` instance (such as `"timestamp-nanos"` on Avro < 1.12), check
`unwrapped.getProp("logicalType") == null` (or `value instanceof Number`), or
move the `switch (unwrapped.getType())` inside the
`BYTE`/`INT16`/`INT32`/`INT64`/`FLOAT`/`DOUBLE` branch of `switch
(fieldType.getTypeName())`.
```suggestion
if (unwrapped.getLogicalType() == null &&
unwrapped.getProp("logicalType") == null) {
```
--
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]