Skip to content

Tracking: performance PRs ported from pasta #2175

Backlog

Description

@BenjaminDEMAILLE

I opened a batch of performance PRs across htslib, samtools, bcftools and htscodecs in one go, which is a lot to review. I've put them all here with what each one gains and what it depends on, so you can tell me which are worth your time. I'm happy to close or draft the rest.

All of them came from comparing against pasta (https://github.com/DylanCosto/pasta, MIT), a Rust reimplementation, and porting the ideas that measured faster. Each one keeps the output identical to develop and passes the repo's tests.

I measured everything on an Apple M4 Max, mostly as the median of 5 runs. The VCF data is 1000 Genomes chr22:16-26Mb with 500 samples. The BAM/CRAM data is GIAB HG003 Illumina chr20:10-20M (3.7M reads) and HG002 HiFi chr20:10-30M. The machine was busy during some runs (#2174 in particular), so treat small differences as noise.

PR Change Command develop PR Speedup
#2174 parse and format VCF on the thread pool bcftools view --threads 4 -Ou (VCF.gz) 2.77 s 0.89 s 3.1x
bcftools view --threads 8 -Ov (BCF) 2.96 s 0.62 s 4.8x
bcftools stats --threads 8 0.69 s 0.30 s 2.3x
#2171 GT-only FORMAT parse fast path bcftools view -Ou (VCF.gz) 1.72 s 0.49 s 3.5x
bcftools stats -s - 2.60 s 1.38 s 1.9x
#2172 diploid GT write fast path bcftools view -Ov (BCF) 1.42 s 0.33 s 4.3x
bcftools query -f '[%GT\t]\n' 1.79 s 1.14 s 1.6x
#2173 CRAM_OPT_REQUIRED_TAGS samtools view -c -d AS:0 (CRAM, CPU) 0.90 s 0.54 s 1.7x
samtools/samtools#2434 view -c uses it (needs #2173) same 0.90 s 0.54 s 1.7x
#2176 skip CRAM blocks the required fields do not use samtools flagstat -@4 (HiFi CRAM ×10) 0.36 s / 100 MB 0.06 s / 15 MB 6x
samtools flagstat (Illumina CRAM) 0.36 s / 19.6 MB 0.35 s / 15.5 MB RAM −21%
samtools/samtools#2349 thread pool in merge, view -U, mpileup, bedcov, coverage mpileup input decompression 57.6 s 53.9 s 1.07x
samtools/samtools#2433 BAQ on threads (on top of #2349) samtools mpileup -f ref -@8 57.6 s 9.2 s 6.3x
samtools/samtools#2431 cheaper per-base counting samtools stats Illumina 4.10 s 2.90 s 1.4x
samtools stats HiFi 10.07 s 6.56 s 1.5x
samtools/samtools#2432 per-cycle counting on threads (on top of #2431) samtools stats -@8 Illumina 2.96 s 1.31 s 2.3x
samtools stats -@8 HiFi 7.30 s 2.04 s 3.6x
samtools/samtools#2436 stats coverage as depth changes per block samtools stats cycles, Illumina / HiFi 15.99 / 39.26 G 15.55 / 38.25 G 1.03x
samtools/samtools#2430 markdup hash, bam1_t reuse samtools markdup -u (8M reads) 4.74 s 3.65 s 1.3x
samtools markdup -@8 3.54 s 3.29 s 1.08x
samtools/bcftools#2621 mpileup chunks on threads bcftools mpileup -a AD,DP --threads 8 BAM 43.5 s 10.0 s 4.3x
same on CRAM 93.2 s 16.4 s 5.7x
samtools/bcftools#2618 concat copies BGZF blocks bcftools concat 4x VCF.gz 2.76 s 0.18 s 15.7x
bcftools concat 4x BCF 2.38 s 0.15 s 16.0x
samtools/bcftools#2619 stats 0/0 shortcut bcftools stats -s - BCF 1.09 s 0.47 s 2.3x
bcftools stats -s - VCF.gz 2.65 s 1.84 s 1.4x
samtools/bcftools#2620 norm decodes each tag once bcftools norm -m- -Ou (CPU) 2.39 s 1.86 s 1.3x
samtools/htscodecs#162 name tokeniser trie in one pass tok3 encode level 3, Illumina names 98 MB/s 138 MB/s 1.41x
same, HiFi names 96 MB/s 112 MB/s 1.17x
samtools/htscodecs#164 token arrays allocated in chunks tok3 decode, 10k Illumina names 564 MB/s 1096 MB/s 1.94x
tok3 encode, 1k HiFi names 88 MB/s 101 MB/s 1.15x
samtools/htscodecs#165 path-compressed trie (on top of #162) tok3 encode, Illumina / HiFi names 126 / 102 MB/s 141 / 114 MB/s 1.12x
samtools/htscodecs#163 16-bit rANS 4x8 order-1 symbols order-1 decode, Illumina quals 584 MB/s 615 MB/s 1.05x
same, HiFi quals 339 MB/s 377 MB/s 1.11x

samtools/samtools#2435 isn't a performance change. MSYS2 dropped mingw-w64-x86_64-tools-git, so build-windows fails on every samtools PR until it goes in.

With #162, #164 and #165 together, tok3 encodes Illumina names at 162 MB/s, ahead of pasta's 150. With #2172 and #2174, bcftools view --threads 8 -Ov takes 0.16 s against 0.24 s for pasta.

If I had to pick, I'd keep #2174, samtools/bcftools#2621, samtools/samtools#2433, #2171/#2172 and the CI fix. The small ones (markdup with threads, norm, #163) are the easiest to drop.

Assisted-by: Claude:claude-opus-5-5

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions