From a29abb9cf452b4b85a367af11c446bf2430aa5a9 Mon Sep 17 00:00:00 2001 From: Bingfeng Date: Mon, 16 Mar 2020 16:01:26 -0700 Subject: [PATCH] Check isDebugEnabled in FastGenericDatumReader/Writer for better performance (#30) Co-authored-by: Bingfeng Xia --- .../fastserde/FastGenericDatumReader.java | 20 +++++++++++++------ .../fastserde/FastGenericDatumWriter.java | 19 ++++++++++++------ 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/avro-fastserde/src/main/java/com/linkedin/avro/fastserde/FastGenericDatumReader.java b/avro-fastserde/src/main/java/com/linkedin/avro/fastserde/FastGenericDatumReader.java index d9c3149e8..1ab8e465e 100644 --- a/avro-fastserde/src/main/java/com/linkedin/avro/fastserde/FastGenericDatumReader.java +++ b/avro-fastserde/src/main/java/com/linkedin/avro/fastserde/FastGenericDatumReader.java @@ -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"); + } } } @@ -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 + "]"); + } } } diff --git a/avro-fastserde/src/main/java/com/linkedin/avro/fastserde/FastGenericDatumWriter.java b/avro-fastserde/src/main/java/com/linkedin/avro/fastserde/FastGenericDatumWriter.java index 974af1175..badfc4d5a 100644 --- a/avro-fastserde/src/main/java/com/linkedin/avro/fastserde/FastGenericDatumWriter.java +++ b/avro-fastserde/src/main/java/com/linkedin/avro/fastserde/FastGenericDatumWriter.java @@ -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"); + } } } @@ -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 + "]"); + } } }