Repository navigation
Compress read names with tok3 in blocks of 10,000 records - #114
Merged
mvassilev merged 1 commit intoOct 18, 2026
Merged
Conversation
Read names were a string column compressed by zstd page by page, 111.4 MB of the 531.0 MB file on chr20 of NA12878 at 30x. CRAM 3.1 compresses names with tok3, htscodecs' name tokeniser, which codes each name against the ones before it. The converters now collect the names of every 10,000 records, the blocks the -fqzcomp qualities already use, and com-fqzc them with tok3 at level 3 without arithmetic coding. The last row of a block carries it in the new field nameblock, and METADATA's qual_block_ends becomes block_ends. qname stays in RAMNTupleRecord for writing, but is transient and no longer a column. NameBlockReader gives the name of any row: it decodes one block at a time and, while the rows come in order, the next two ahead on other threads. QualityBlocks.h becomes RecordBlocks.h and QualityBlockWriter becomes BlockWriter, which writes both kinds of block. htscodecs is built from the sources the tokeniser needs as well, still without SIMD or bzip2, as ramtools::htscodecs. The format version becomes 7. On all of chr20 the file goes from 531.0 to 478.2 MB from SAM and from 530.7 to 477.7 MB from BAM. The md5 of ramdump -h is the input's for SAM and that of samtools view for BAM, as before, and flagstat and idxstats print the same. Regions of 500 to 2,000 bp take 0.3 to 0.4 s on both sides. Reading every name costs CPU, because htscodecs' decoder allocates and frees memory for each name. On macOS, ramdump -h of the whole file takes 27.8 to 28.4 s and 33.6 to 34.0 s of CPU, against 25.9 to 27.3 s and 25.8 to 27.1 s; a 10 Mb region 5.3 to 6.0 s and 6.3 to 7.1 s of CPU, against 5.2 to 5.3 s and 5.0 to 5.3 s. Removing the decoder's per-name realloc in a patched copy gave no clear gain, so htscodecs is used as released. On the 2 million record subset, five runs in alternating order, conversion takes the same CPU: 27.1 against 27.6 s from SAM, 24.6 against 27.9 s with -threads 4, and 23.9 against 24.7 s from BAM (medians), with 5 to 12 MB more at the peak.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## develop #114 +/- ##
===========================================
+ Coverage 88.64% 88.69% +0.05%
===========================================
Files 25 25
Lines 3029 3115 +86
Branches 995 1050 +55
===========================================
+ Hits 2685 2763 +78
- Misses 185 188 +3
- Partials 159 164 +5
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
|
|
||
| #include <ROOT/REntry.hxx> | ||
| #include <ROOT/RNTupleReader.hxx> | ||
| #include <ROOT/RNTupleTypes.hxx> |
There was a problem hiding this comment.
warning: included header RNTupleReader.hxx is not used directly [misc-include-cleaner]
Suggested change
| #include <ROOT/RNTupleTypes.hxx> | |
| #include <ROOT/RNTupleTypes.hxx> |
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.
Read names were a string column compressed by zstd page by page, 111.4 MB of the 531.0 MB file on chr20 of NA12878 at 30x. CRAM 3.1 compresses names with tok3, htscodecs' name tokeniser, which codes each name against the ones before it.
The converters now collect the names of every 10,000 records, the blocks the -fqzcomp qualities already use, and com-fqzc them with tok3 at level 3 without arithmetic coding. The last row of a block carries it in the new field nameblock, and METADATA's qual_block_ends becomes block_ends. qname stays in RAMNTupleRecord for writing, but is transient and no longer a column. NameBlockReader gives the name of any row: it decodes one block at a time and, while the rows come in order, the next two ahead on other threads. QualityBlocks.h becomes RecordBlocks.h and QualityBlockWriter becomes BlockWriter, which writes both kinds of block. htscodecs is built from the sources the tokeniser needs as well, still without SIMD or bzip2, as ramtools::htscodecs. The format version becomes 7.
On all of chr20 the file goes from 531.0 to 478.2 MB from SAM and from 530.7 to 477.7 MB from BAM. The md5 of ramdump -h is the input's for SAM and that of samtools view for BAM, as before, and flagstat and idxstats print the same. Regions of 500 to 2,000 bp take 0.3 to 0.4 s on both sides.
Reading every name costs CPU, because htscodecs' decoder allocates and frees memory for each name. On macOS, ramdump -h of the whole file takes 27.8 to 28.4 s and 33.6 to 34.0 s of CPU, against 25.9 to 27.3 s and 25.8 to 27.1 s; a 10 Mb region 5.3 to 6.0 s and 6.3 to 7.1 s of CPU, against 5.2 to 5.3 s and 5.0 to 5.3 s. Removing the decoder's per-name realloc in a patched copy gave no clear gain, so htscodecs is used as released.
On the 2 million record subset, five runs in alternating order, conversion takes the same CPU: 27.1 against 27.6 s from SAM, 24.6 against 27.9 s with -threads 4, and 23.9 against 24.7 s from BAM (medians), with 5 to 12 MB more at the peak.