spike(writer): FFM binding to system libzstd vs aircompressor#163
Closed
dfa1 wants to merge 1 commit into
Closed
Conversation
Owner
Author
|
this will be closed by using this library: https://github.com/dfa1/zstd-java (JDK 25 + MemorySegment native) |
Throwaway exploration (test scope) probing whether core's vortex.zstd codec can move off the unmaintained aircompressor onto native libzstd via FFM downcalls (no JNI, no Unsafe). ZstdNative binds ZSTD_compressBound/compress/decompress/isError through Linker, resolving the system libzstd (-Dzstd.lib.path override; graceful available() check for fallback). ZstdFfmSpikeTest measures ratio/speed on real OHLC column bytes and asserts frame compatibility both directions. Findings (1M rows, libzstd 1.5.7): native and aircompressor decode each other's frames, so the on-disk format is unchanged. Native compress ~2x faster at equal ratio (level 3), with a real ratio knob at higher levels; decompress 1.1-1.4x faster even through the spike's heap bounce. Native also supports dictionaries, which the pure-Java decoder rejects. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
What
Throwaway spike (test scope only) probing whether core's
vortex.zstdcodec can move off the unmaintained aircompressor onto native libzstd via FFM downcalls — no JNI, noUnsafe.Motivation: aircompressor is effectively unmaintained (PRs/issues ignored), yet it's load-bearing in core — both
ZstdEncodingEncoderandZstdEncodingDecoderride it. zstd-jni was ruled out (its bundled blob statically links libzstd with theZSTD_*C symbols hidden — only the JNI entry points are exported, so FFM can't borrow it; and it's JNI anyway).How
ZstdNative— bindsZSTD_compressBound/compress/decompress/isErrorthroughLinkerdowncalls. Resolves the system libzstd from well-known paths (-Dzstd.lib.path=...override);available()reports load success so callers can fall back to the pure-Java path when no native lib is present.ZstdFfmSpikeTest— measures ratio/speed on real OHLC column bytes and asserts frame compatibility both directions. Skips when no system libzstd is present.Spike copies through heap
byte[]for an apples-to-apples comparison; a real codec would work straight on arena segments.Findings (1M rows, libzstd 1.5.7)
Frame-compatible both ways (test passes): native and aircompressor decode each other's frames → the on-disk
vortex.zstdformat is unchanged regardless of which side writes it. This is the gate, and it's green.byte[]. A real decoder writing into the scan arena would be faster and satisfy the off-heap rule (today's decoder violates it withtoArray()+new byte[]).dictionary_size != 0. The wire field already exists.Not in scope (follow-up if we promote)
Move
ZstdNativeto core/main, wireZstdEncodingEncoder/Decoderto it with aircompressor fallback, decode straight into the arena, add dictionary support. Bundling libzstd (vs require-system-lib) is a separate packaging decision.🤖 Generated with Claude Code