Repository navigation
Conversation
|
Ohhh, yes, that's exactly the stuff I need for my 0 allocations parquet library. |
|
I'm sorry for my late reply, I've been meaning to get back to this. I do like the idea here, but I have one concern. Originally, those backing classes were kept internal to control the public API surface. Once public, it becomes a breaking change if we perform any refactoring. I'm not in love with the current API surface of them for a public-facing scenario. I think we should spend some time looking at it and cleaning it up some to make sure we're 100% happy before making it public. In particular, I think we should consider methods that return OpertionStatus with values like |
|
No worries! And agreed — exposing the internal classes as-is locks things in more than it's worth. How about this instead: keep For decompression, something shaped like public sealed class SnappyBlockDecoder : IDisposable
{
public OperationStatus Decompress(ReadOnlySpan<byte> source, Span<byte> destination,
out int bytesConsumed, out int bytesWritten);
// one-shot convenience: resets automatically, throws on bad data
public void Decompress(ReadOnlySequence<byte> source, IBufferWriter<byte> destination);
public void Reset(); // start a new block, keep working memory
public void Dispose();
}
For compression I'd deliberately not use public sealed class SnappyBlockEncoder : IDisposable
{
public int Compress(ReadOnlySpan<byte> source, Span<byte> destination); // throws if too small
public bool TryCompress(ReadOnlySpan<byte> source, Span<byte> destination, out int bytesWritten);
public void Compress(ReadOnlySequence<byte> source, IBufferWriter<byte> destination);
public void Dispose();
}(I did consider skipping new types entirely and just caching the working memory inside the static methods — that fixes the per-call allocations but gives no streaming story, so I dropped it.) One question: after If this direction works for you I'll rework the PR to match. |
|
Overall, I think this is a solid plan. My one recommendation is that we should do a PR just for the internal refactoring to use |
Expose stable encoder and decoder wrappers while keeping codec internals free to evolve. Refs brantburnett#148
Expose reusable raw-block compressor and decompressor lifecycles.
Motivation
High-throughput callers currently use the static block APIs, which construct a codec driver per block. Dekaf measured 48-50 B for compression and 80-81 B for decompression per call. Reflection or unsafe access to the internal engines is incompatible with Native AOT and trimming.
This is the upstream prerequisite for Dekaf #2352.
Solution
SnappyCompressorandSnappyDecompressorsupported public sealed types.IBufferWriter<byte>destination.The static
SnappyAPIs retain their existing behavior and delegate to the reusable engine.Validation
dotnet build Snappier.slnx --configuration Release: 0 warnings/errors.1.3.2).IsAotCompatibleanalyzers pass cleanly.BenchmarkDotNet 0.15.2, .NET 10, DefaultJob, 64 KiB HTML block:
A package release containing this API would let downstream callers consume it without reflection or vendoring.