Permalink
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...
1 parent 2bd0d5b commit 47d4714556ecb6c3454b2c1ae7910050d3c1b372 @toddlipcon toddlipcon committed Sep 1, 2011
Showing with 8 additions and 1 deletion.
  1. +8 −1 src/java/com/hadoop/compression/lzo/LzoCompressor.java
@@ -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);

0 comments on commit 47d4714

Please sign in to comment.