Repository navigation
Faster single-core tile compression - #12
Merged
Merged
Conversation
The encoder writes through a 64-bit accumulator four bytes at a time into a pooled buffer, reserves room once for each block, merges the unary part with the low bits into one write and sums the differences in an integer. The bytes are those of the previous encoder, which the tests keep as a reference. One core, 3536 x 3536 16-bit frame: 138 ms to 66 ms (cfitsio: 68 ms).
…st for each value The Rice decoder reads from a 64-bit window refilled eight bytes at a time, takes a unary code and the low bits with one shift, and undoes the zigzag mapping without a branch. A code that no encoder writes (an FS code above the maximum for 4-byte pixels) is now refused with a FitsException instead of giving pixels that depended on a register overflow. The dequantization works on runs of the dither sequence, which has no wrap inside: 60 ms to 13 ms for a 3536 x 3536 float frame, the same values bit for bit (the first versions are kept in the tests).
The bit writer works through a 64-bit accumulator four bytes at a time. The signs of the coefficients and the bits of the quadtree codes are counted without a branch. CompressionOptions.GzipLevel (-1 by default, the same bytes as before) chooses the zlib level of GZIP_1 and GZIP_2: from .NET 9 level 2 gives files about as large as cfitsio's in about the same time.
The Rice reader never fills its window to 64 bits (a shift by 64 is a shift by 0). The unary quotient of the encoder is unsigned, the initial capacity is computed without overflow, and the buffers are returned when an allocation fails. New tests: an FS code that no encoder writes is refused, short random buffers decode like the first decoder up to the last bit, tiles compressed on all cores give the bytes of one core. The documentation says that GzipLevel is ignored by tables.
…bles accept the GzipLevel rows
sputier
force-pushed
the
perf/1-single-core-codecs
branch
from
November 14, 2026 21:03
69b49ad to
bfdb208
Compare
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.
Refs #1.
What changes
Single-core tile compression was slower than cfitsio (
docs/comparison.md). This branch makes the codecs faster without changing the files they write.FitsException(it used to give pixels that depended on a register overflow).BitWriter(also used by theHCOMPRESSencoder) works through a 64-bit accumulator; the signs of the coefficients and the sizes of the quadtree codes are computed without a branch.CompressionOptions.GzipLevel(new, default -1: the data of before): the zlib level ofGZIP_1andGZIP_2. At the default level the files are about 6 percent smaller than cfitsio's and take about twice as long to write; from .NET 9, level 2 gives about cfitsio's size and time. Ignored for tables.Measured
Old (
main) and new code in the same process, called in turn 21 times (the drift of the machine hits both the same way), 3536 x 3536 16-bit frame, one core:BenchmarkDotNet,
mainagainst the branch, alternating: Rice compression 138 ms to 75 ms, decompression of the quantized float image 139 ms to 91 ms.Checks
tests/Eleris.FitsNet.Tests/Reference*.cs,DequantizeTests,BitWriterTests,RiceEncoderTests,RiceDecoderTests) and compare bytes and bit patterns, including a differential fuzz on damaged data. 2003 tests pass on net8.0 and net10.0.af48774.Not in this PR
docs/comparison.mdstill shows the figures measured before these changes. The new figures against cfitsio need a machine with nothing else running (other work on the machine made the measures of the last attempt unusable), so #1 stays open until the page is refreshed.