Repository navigation
Conversation
LZ4FrameInputStream rejected frames with linked blocks (FLG.B.Indep = 0), although they are the default of liblz4's frame API (LZ4F_blockLinked = 0). In such frames, a block may reference up to 64 KB of the data decoded before it in the same frame. LZ4FrameOutputStream still writes independent blocks only. The templates generate a separate decompressWithPrefix copy of the safe decoder, for byte arrays, whose matches may also reach the prefixLen bytes before destOff in dest. The existing decompress methods keep the same bytecode: a variant sharing their code made the safe decoder 3 to 5% slower on independent blocks with JDK 21 and 25, a code generation effect. JNI gets a new native, LZ4_decompress_safe_usingDict, for which liblz4 detects the prefix in place. The existing natives are unchanged. decompressWithPrefix is package-private and not abstract on LZ4SafeDecompressor. Implementations outside this package keep working, and reject a non-empty prefix. LZ4FrameInputStream decodes a linked block right after the data decoded before it in the frame, and moves the last 64 KB of that data to the start of the buffer only when the block doesn't fit after it. The buffer grows to at most 64 KB + the maximum block size, still only as data arrives. Blocks without history (independent blocks, first block of a linked frame) still go through decompress(), which also keeps them working with an older native library from java.library.path. FLG.fromByte accepts linked blocks; the FLG constructor, used by LZ4FrameOutputStream, still rejects them. LZ4FrameLinkedBlocksTest writes linked frames by hand along with their content: matches up to offset 65535 across several blocks, matches before the frame start, no history across frames, random concatenated frames. It also decodes frames written by the lz4 CLI with -BD (each block size, -BX, --content-size, -9), checked to depend on the history, with the three decompressors. New fuzz targets decompress with a prefix twice, with different data before the prefix and after the output, and compare; LZ4TestAccess gives them access to the package-private method. The frame fuzz targets get a seed with linked frames. Decoding speed on silesia, lz4 CLI frames, JDK 25: unchanged for independent blocks. Linked vs independent blocks of the same size: JNI -0.4% with 256 KB and 4 MB blocks, +8% with 64 KB blocks (better ratio); safe decoder -3% with 256 KB and 4 MB blocks, +8% with 64 KB blocks.
This branch has not been deployed
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
LZ4FrameInputStream now decodes frames with linked blocks, the default of liblz4's frame API. Decompression only: LZ4FrameOutputStream still writes independent blocks.
Existing decoders are unchanged. Details, tests and measurements are in the commit message.
Closes #197