Skip to content

perf(tabix): reuse the line buffer across records (no per-record malloc) - #83

Merged
balwierz merged 1 commit into
mainfrom
perf/tabix-kstring
Jul 10, 2026
Merged

perf(tabix): reuse the line buffer across records (no per-record malloc)#83
balwierz merged 1 commit into
mainfrom
perf/tabix-kstring

Conversation

@balwierz

Copy link
Copy Markdown
Owner

Summary

TabixInputStream::fetch_next_line declared a fresh kstring_t on every call, so each record streamed through a bgzipped -r range query (VCF/BED/GFF/TSV .gz) paid an htslib malloc + a free. It now keeps one buffer for the whole scan — htslib's bgzf_getline resets the length and reallocs only when a line outgrows it — freed once in the destructor.

Verification

  • Output byte-identical — verified by hashing a -r chr1:1-3e7 query over a 1 M-record tabix BED, old vs new.
  • Small steady-state gain (~3% on that scan) and no per-record allocator churn.
  • Existing tabix VCF/BED/GFF/mpileup region tests still pass; suite 375; the ASan/UBSan gate exercises the reused buffer (no UAF).

🤖 Generated with Claude Code

…rd malloc

TabixInputStream::fetch_next_line declared a fresh kstring_t on every call, so
each record streamed through a bgzipped `-r` range query paid an htslib
malloc + a free. Make the kstring a member reused across the whole scan
(htslib's bgzf_getline resets its length and reallocs only when a line outgrows
the buffer), freed once in the destructor.

Output byte-identical (verified on a 1 M-record tabix BED); a small steady-state
gain (~3% on that scan) and no per-record allocator churn. Suite 375.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@balwierz
balwierz merged commit 9aced81 into main Jul 10, 2026
3 checks passed
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