Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix performance issue when reinit() is called with a null Configuration

Previously, this would instantiate a new Configuration object on every call,
which involved re-reading and parsing the configuration XML files to
load the defaults. This was very slow.

The new version caches a default Configuration object statically
and uses that one in this circumstance.
  • Loading branch information...
commit 47d4714556ecb6c3454b2c1ae7910050d3c1b372 1 parent 2bd0d5b
Todd Lipcon toddlipcon authored
Showing with 8 additions and 1 deletion.
  1. +8 −1 src/java/com/hadoop/compression/lzo/LzoCompressor.java
9 src/java/com/hadoop/compression/lzo/LzoCompressor.java
View
@@ -59,6 +59,13 @@
private ByteBuffer workingMemoryBuf; // The 'working memory' for lzo.
/**
+ * Used when the user doesn't specify a configuration. We cache a single
+ * one statically, since loading the defaults is expensive.
+ */
+ private static Configuration defaultConfiguration =
+ new Configuration();
+
+ /**
* The compression algorithm for lzo library.
*/
public static enum CompressionStrategy {
@@ -199,7 +206,7 @@ public void reinit(Configuration conf) {
// and the new user of the codec doesn't specify a particular configuration
// to CodecPool.getCompressor(). So we use the defaults.
if (conf == null) {
- conf = new Configuration();
+ conf = defaultConfiguration;
}
LzoCompressor.CompressionStrategy strategy = LzoCodec.getCompressionStrategy(conf);
int bufferSize = LzoCodec.getBufferSize(conf);
Please sign in to comment.
Something went wrong with that request. Please try again.