iemejia commented on code in PR #3865:
URL: https://github.com/apache/avro/pull/3865#discussion_r3567597330
##########
lang/java/avro/src/main/java/org/apache/avro/generic/GenericDatumReader.java:
##########
@@ -364,7 +400,7 @@ protected Object readMap(Object old, Schema expected,
ResolvingDecoder in) throw
LogicalType logicalType = eValue.getLogicalType();
Conversion<?> conversion = getData().getConversionFor(logicalType);
ensureAvailableMapBytes(in, l, eValue);
- Object map = newMap(old, (int) l);
+ Object map = newMap(old, initialCollectionCapacity(l));
if (l > 0) {
Review Comment:
Same intentional tradeoff as readArray (see the earlier thread): the clamp
is only the *initial* capacity — the map still grows to hold every entry read,
with amortized O(n) growth — so for a legitimate large in-memory map it costs a
few extra resizes rather than a single up-front allocation. Keeping it
unconditional covers the stream case (remainingBytes() == -1) and keeps the
code simple; a remaining-aware refinement can follow if profiling shows it
matters.
--
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]