Skip to content

Compress read names with tok3 in blocks of 10,000 records - #114

Merged
mvassilev merged 1 commit into
compiler-research:developfrom
mvassilev:feature/name-blocks
Oct 18, 2026
Merged

mvassilev merged 1 commit into
compiler-research:developfrom
mvassilev:feature/name-blocks

Conversation

@mvassilev

Copy link
Copy Markdown
Collaborator

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.

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-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.64706% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.69%. Comparing base (a03b3e8) to head (2ecd2b9).

Files with missing lines Patch % Lines
src/ramcore/RecordBlocks.cxx 90.78% 3 Missing and 4 partials ⚠️
test/bam_conversion.cxx 71.42% 0 Missing and 2 partials ⚠️
test/record_blocks_test.cxx 95.65% 0 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@             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     
Flag Coverage Δ
unittests 88.69% <92.64%> (+0.05%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
inc/ramcore/RecordBlocks.h 100.00% <100.00%> (ø)
inc/rntuple/RAMNTupleRecord.h 100.00% <ø> (ø)
src/ramcore/BamtoNTuple.cxx 88.35% <100.00%> (ø)
src/ramcore/SamToNTuple.cxx 89.53% <100.00%> (+0.02%) ⬆️
src/rntuple/RAMFile.cxx 92.45% <100.00%> (ø)
src/rntuple/RAMNTupleRecord.cxx 79.06% <100.00%> (+0.09%) ⬆️
test/parallel_conversion_test.cxx 98.69% <100.00%> (+0.01%) ⬆️
test/ramcoretests.cxx 100.00% <100.00%> (ø)
tools/ramdump.cxx 85.71% <100.00%> (ø)
test/record_blocks_test.cxx 97.56% <95.65%> (ø)
... and 2 more
Files with missing lines Coverage Δ
inc/ramcore/RecordBlocks.h 100.00% <100.00%> (ø)
inc/rntuple/RAMNTupleRecord.h 100.00% <ø> (ø)
src/ramcore/BamtoNTuple.cxx 88.35% <100.00%> (ø)
src/ramcore/SamToNTuple.cxx 89.53% <100.00%> (+0.02%) ⬆️
src/rntuple/RAMFile.cxx 92.45% <100.00%> (ø)
src/rntuple/RAMNTupleRecord.cxx 79.06% <100.00%> (+0.09%) ⬆️
test/parallel_conversion_test.cxx 98.69% <100.00%> (+0.01%) ⬆️
test/ramcoretests.cxx 100.00% <100.00%> (ø)
tools/ramdump.cxx 85.71% <100.00%> (ø)
test/record_blocks_test.cxx 97.56% <95.65%> (ø)
... and 2 more
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@mvassilev
mvassilev merged commit acb8904 into compiler-research:develop Oct 18, 2026
4 checks passed

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions


#include <ROOT/REntry.hxx>
#include <ROOT/RNTupleReader.hxx>
#include <ROOT/RNTupleTypes.hxx>

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: included header RNTupleReader.hxx is not used directly [misc-include-cleaner]

Suggested change
#include <ROOT/RNTupleTypes.hxx>
#include <ROOT/RNTupleTypes.hxx>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants