Repository navigation
Read ahead blocks only within the records' cluster - #132
Merged
Merged
Conversation
A full read read each cluster several times: 2.04 GB for chromosome 20's 418 MB file, 6.6 GB for HiSeq chromosome 20's 2.2 GB. ROOT's cluster cache keeps the cluster it is asked for and the next one; the block readers read ahead at the last row of each block, near the end of a cluster in the next one, and so dropped the cluster the records were still in, which they then read again. Every block lies in one cluster, so the readers of names, qualities and bases now read ahead only blocks of their block's cluster, when the file is read with the cluster cache. A block of fqzcomp, 25 times slower to decode, still reads ahead from the next cluster. RAMFile says whether its reader uses the cache. A test checks with ROOT's metrics that a full read reads no more than the file holds. On z840, against #131: HiSeq chromosome 20 reads 2.17 GB, in 19.3 to 19.9 s instead of 23.8 to 24.4 s, with 1.3 s of system time instead of 6.0 s; chromosome 20 reads 0.42 GB, in 14.5 to 15.2 s instead of 15.1 to 16.0 s. Regions, -@ N and fqzcomp files take the same time.
mvassilev
force-pushed
the
cluster-read-ahead
branch
from
November 8, 2026 08:55
fa82542 to
95fd1c1
Compare
| const std::string bases = "ACGT"; | ||
| std::vector<Read> reads; | ||
| for (std::size_t i = 0; i < kReads; i++) | ||
| reads.push_back({0, std::string(kLength, static_cast<char>('!' + i % 40)), "read" + std::to_string(i), |
There was a problem hiding this comment.
warning: '%' has higher precedence than '+'; add parentheses to explicitly specify the order of operations [readability-math-missing-parentheses]
Suggested change
| reads.push_back({0, std::string(kLength, static_cast<char>('!' + i % 40)), "read" + std::to_string(i), | |
| reads.push_back({0, std::string(kLength, static_cast<char>('!' + (i % 40))), "read" + std::to_string(i), |
| const std::string bases = "ACGT"; | ||
| std::vector<Read> reads; | ||
| for (std::size_t i = 0; i < kReads; i++) | ||
| reads.push_back({0, std::string(kLength, static_cast<char>('!' + i % 40)), "read" + std::to_string(i), |
There was a problem hiding this comment.
warning: 'push_back' is called inside a loop; consider pre-allocating the container capacity before the loop [performance-inefficient-vector-operation]
test/record_blocks_test.cxx:380:
- for (std::size_t i = 0; i < kReads; i++)
+ reads.reserve(kReads);
+ for (std::size_t i = 0; i < kReads; i++)
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #132 +/- ##
===========================================
+ Coverage 89.38% 89.41% +0.02%
===========================================
Files 26 26
Lines 3722 3789 +67
Branches 1267 1289 +22
===========================================
+ Hits 3327 3388 +61
- Misses 203 204 +1
- Partials 192 197 +5
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
|
clang-tidy review says "All clean, LGTM! 👍" |
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.
A full read of a RAM file reads each cluster several times:
stracecounts 2.04 GB ofpreadfor chromosome 20's 418 MB file, and 6.6 GB for the 2.2 GB file of NA12878's HiSeq chromosome
20. The cause is ROOT's cluster cache and the block readers. On a request for a cluster, the
cache keeps that cluster and the next one and drops the rest (
RClusterPool::GetCluster). Thereaders of names, qualities and bases read ahead two, four and one blocks, each at the last row
of its block. Near the end of a cluster those rows are in the next cluster, so the request drops
the cluster the records are still in, and the next page a record needs from it reads it again.
Every block lies in one cluster: on chromosome 20 (138 clusters, 1,863 blocks), HiSeq (148,
1,479), the whole genome converted from BAM (5,006, 78,644) and a file written on one thread,
since the writers end a cluster with the input block and the quality block with it.
The change
FlaggedBlockReaderandNameBlockReaderknow the cluster of each block, and read aheadonly blocks of the cluster of the block they are in. The first block of the next cluster is
decoded when the records reach it.
of each cluster made a full read of 2 million records 5.5 to 5.9 s instead of 4.4 to 4.5 s,
so after such a block the quality reader reads ahead from the next cluster as before.
RAMFile::UsesClusterCache()now says.ramdumpreadsregions without it, page by page: there the cache drops nothing, and the wait made a 10 Mb
region 3.07 to 3.18 s instead of 2.89 to 3.03 s.
that a full read reads no more than the file holds: 21,396 bytes of 8,886 before.
Tried and dropped: pinning the records' cluster with
RNTupleReader::CreateActiveEntryToken().The cache then keeps it, but without implicit multithreading ROOT keeps every page released
from a pinned cluster until the reader closes, all of the decoded file in a full read. A
second reader for the block columns would double the cost of opening, 0.36 s and 115 MB on
the whole genome, for every region.
What it does
z840 socket 0, on top of #131, against #131, in turn, both on 0.2.0's files; the outputs are
the same, and
ramdump -hgives back the SAM files' md5 on chromosome 20 and HiSeq:Three to six runs each. Unchanged:
-@ 8on chromosome 20 (4.97 to 5.16 s), a 10 Mb regionof chromosome 20 (2.96 to 3.01 s against 2.90 to 2.97 s) and of chromosome 1 on the whole
genome (2.59 to 2.69 s against 2.58 to 2.61 s), a 1 kb region in a process of its own (0.06 s
on chromosome 20, 0.44 to 0.53 s on the whole genome).
14 of 14 tests pass on z840 (ROOT 6.40.04, htslib 1.25); the new test fails without the change.
This branch starts from #131's, so it is best merged after it.
Changelog
of 23.8 to 24.4 s.