Skip to content

concat: copy unchanged BGZF blocks instead of recompressing - #2618

Open
BenjaminDEMAILLE wants to merge 1 commit into
samtools:developfrom
BenjaminDEMAILLE:perf/concat-copy-blocks
Open

BenjaminDEMAILLE wants to merge 1 commit into
samtools:developfrom
BenjaminDEMAILLE:perf/concat-copy-blocks

Conversation

@BenjaminDEMAILLE

@BenjaminDEMAILLE BenjaminDEMAILLE commented Nov 23, 2026 •

Copy link
Copy Markdown

I noticed that plain bcftools concat decompresses and recompresses everything, even when no record changes. With this change I still read and check the records (same order checks and errors), but I copy the original BGZF blocks to the output. Only the part that shares a block with the header gets recompressed.

I only use it per input when there's no -a/-l/-G/-W and no explicit level, the input is a regular BGZF file of the same format as the output, and, for BCF, the header IDs match. Anything odd (CRLF, no final newline, read errors) falls back to the current path. The decompressed output is identical to develop; only the block boundaries differ. I factored out the --naive block copy loop and reuse it.

Concatenating 4 chunks of 1000G chr22 went from 2.76s to 0.18s for VCF.gz and from 2.38s to 0.15s for BCF on my machine. The output gets about 0.03% bigger.

make test passes. I made test_vcf_concat also check -Oz, and added concat.7 to cover the fallbacks.

I adapted the idea from pasta (https://github.com/DylanCosto/pasta, MIT).

I've listed this with my other performance PRs in samtools/htslib#2175.

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

For a plain concat (no -a/-l/-G/-W or compression level) of inputs in
the output's BGZF format whose records need no change, still read and
check the records but copy the original compressed blocks.  CRLF, no
final newline, read errors or different BCF dictionaries fall back to
the old path.  Decompressed output is identical; block boundaries
differ.  Reuses the --naive block copy loop.

Idea from pasta (https://github.com/DylanCosto/pasta, MIT).

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Benjamin Demaille <benjamin.demaille@icloud.com>

This branch has not been deployed

No deployments
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.

1 participant