-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LUCENE-4702: Terms dictionary compression. (#1126)
Compress blocks of suffixes in order to make the terms dictionary more space-efficient. Two compression algorithms are used depending on which one is more space-efficient: - LowercaseAsciiCompression, which applies when all bytes are in the `[0x1F,0x3F)` or `[0x5F,0x7F)` ranges, which notably include all digits, lowercase ASCII characters, '.', '-' and '_', and encodes 4 chars on 3 bytes. It is very often applicable on analyzed content and decompresses very quickly thanks to auto-vectorization support in the JVM. - LZ4, when the compression ratio is less than 0.75. I was a bit unhappy with the complexity of the high-compression LZ4 option, so I simplified it in order to only keep the logic that detects duplicate strings. The logic about what to do in case overlapping matches are found, which was responsible for most of the complexity while only yielding tiny benefits, has been removed.
- Loading branch information
Showing
25 changed files
with
1,467 additions
and
802 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
lucene/core/src/java/org/apache/lucene/codecs/blocktree/CompressionAlgorithm.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.lucene.codecs.blocktree; | ||
|
||
import java.io.IOException; | ||
|
||
import org.apache.lucene.store.DataInput; | ||
import org.apache.lucene.util.compress.LowercaseAsciiCompression; | ||
|
||
/** | ||
* Compression algorithm used for suffixes of a block of terms. | ||
*/ | ||
enum CompressionAlgorithm { | ||
|
||
NO_COMPRESSION(0x00) { | ||
|
||
@Override | ||
void read(DataInput in, byte[] out, int len) throws IOException { | ||
in.readBytes(out, 0, len); | ||
} | ||
|
||
}, | ||
|
||
LOWERCASE_ASCII(0x01) { | ||
|
||
@Override | ||
void read(DataInput in, byte[] out, int len) throws IOException { | ||
LowercaseAsciiCompression.decompress(in, out, len); | ||
} | ||
|
||
}, | ||
|
||
LZ4(0x02) { | ||
|
||
@Override | ||
void read(DataInput in, byte[] out, int len) throws IOException { | ||
org.apache.lucene.util.compress.LZ4.decompress(in, len, out, 0); | ||
} | ||
|
||
}; | ||
|
||
private static final CompressionAlgorithm[] BY_CODE = new CompressionAlgorithm[3]; | ||
static { | ||
for (CompressionAlgorithm alg : CompressionAlgorithm.values()) { | ||
BY_CODE[alg.code] = alg; | ||
} | ||
} | ||
|
||
/** | ||
* Look up a {@link CompressionAlgorithm} by its {@link CompressionAlgorithm#code}. | ||
*/ | ||
static final CompressionAlgorithm byCode(int code) { | ||
if (code < 0 || code >= BY_CODE.length) { | ||
throw new IllegalArgumentException("Illegal code for a compression algorithm: " + code); | ||
} | ||
return BY_CODE[code]; | ||
} | ||
|
||
public final int code; | ||
|
||
private CompressionAlgorithm(int code) { | ||
this.code = code; | ||
} | ||
|
||
abstract void read(DataInput in, byte[] out, int len) throws IOException; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.