Skip to content

Commit

Permalink
Check isDebugEnabled in FastGenericDatumReader/Writer for better perf…
Browse files Browse the repository at this point in the history
…ormance (#30)

Co-authored-by: Bingfeng Xia <[email protected]>
  • Loading branch information
volauvent and Bingfeng Xia authored Mar 16, 2020
1 parent 819b606 commit a29abb9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,19 @@ public FastGenericDatumReader(Schema writerSchema, Schema readerSchema, FastSerd

if (!Utils.isSupportedAvroVersionsForDeserializer()) {
this.cachedFastDeserializer = getRegularAvroImpl(writerSchema, readerSchema);
LOGGER.debug("Current avro version: " + Utils.getRuntimeAvroVersion() + " is not supported, and only the following"
+ " versions are supported: " + Utils.getAvroVersionsSupportedForDeserializer() + ", so skip the FastDeserializer generation");
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(
"Current avro version: " + Utils.getRuntimeAvroVersion() + " is not supported, and only the following"
+ " versions are supported: " + Utils.getAvroVersionsSupportedForDeserializer()
+ ", so skip the FastDeserializer generation");
}
} else if (!FastSerdeCache.isSupportedForFastDeserializer(readerSchema.getType())) {
// For unsupported schema type, we won't try to fetch it from FastSerdeCache since it is inefficient.
this.cachedFastDeserializer = getRegularAvroImpl(writerSchema, readerSchema);
LOGGER.debug("Skip the FastGenericDeserializer generation since read schema type: " + readerSchema.getType()
+ " is not supported");
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Skip the FastGenericDeserializer generation since read schema type: " + readerSchema.getType()
+ " is not supported");
}
}
}

Expand Down Expand Up @@ -73,8 +79,10 @@ public T read(T reuse, Decoder in) throws IOException {
// don't cache
} else {
cachedFastDeserializer = fastDeserializer;
LOGGER.debug("FastGenericDeserializer was generated and cached for reader schema: [" + readerSchema
+ "], writer schema: [" + writerSchema + "]");
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("FastGenericDeserializer was generated and cached for reader schema: ["
+ readerSchema + "], writer schema: [" + writerSchema + "]");
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,19 @@ public FastGenericDatumWriter(Schema schema, FastSerdeCache cache) {
this.cache = cache != null ? cache : FastSerdeCache.getDefaultInstance();
if (!Utils.isSupportedAvroVersionsForSerializer()) {
this.cachedFastSerializer = getRegularAvroImpl(writerSchema);
LOGGER.debug("Current avro version: " + Utils.getRuntimeAvroVersion() + " is not supported, and only the following"
+ " versions are supported: " + Utils.getAvroVersionsSupportedForSerializer()
+ ", so will skip the FastSerializer generation");
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(
"Current avro version: " + Utils.getRuntimeAvroVersion() + " is not supported, and only the following"
+ " versions are supported: " + Utils.getAvroVersionsSupportedForSerializer()
+ ", so will skip the FastSerializer generation");
}
} else if (!FastSerdeCache.isSupportedForFastSerializer(schema.getType())) {
// For unsupported schema type, we won't try to fetch it from FastSerdeCache since it is inefficient.
this.cachedFastSerializer = getRegularAvroImpl(writerSchema);
LOGGER.debug("Skip the FastGenericSerializer generation since read schema type: " + schema.getType()
+ " is not supported");
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Skip the FastGenericSerializer generation since read schema type: " + schema.getType()
+ " is not supported");
}
}
}

Expand All @@ -54,7 +59,9 @@ public void write(T data, Encoder out) throws IOException {
// don't cache
} else {
cachedFastSerializer = fastSerializer;
LOGGER.debug("FastSerializer has been generated and cached for writer schema: [" + writerSchema + "]");
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("FastSerializer has been generated and cached for writer schema: [" + writerSchema + "]");
}
}
}

Expand Down

0 comments on commit a29abb9

Please sign in to comment.