Skip to content

Speed up mpileup by reducing passes through arrays and qual#1995

Merged
daviesrob merged 2 commits into
samtools:developfrom
jkbonfield:mpileup-speed
Mar 8, 2024
Merged

Speed up mpileup by reducing passes through arrays and qual#1995
daviesrob merged 2 commits into
samtools:developfrom
jkbonfield:mpileup-speed

Conversation

@jkbonfield

Copy link
Copy Markdown
Contributor

The code has multiple passes through plp[i] getting ther qualities and comparing against conf->min_baseQ. This is done for printing the depth, which sequence bases to display, as well as obviously the quality values. All 3 of these are now computed in a single step, putting the values into kstrings.

We still have additional excess loops if we ask for the optional columns, but that's not the default output and can be dealt with at a later stage.

Also remove some of the excess seq_nt16_table and seq_nt_str back and forth, plus specialise for strand so we don't also have to call toupper and tolower plus detection of the "=" code.

The combined speed up is 20-25% on the BAM files I tested (long and short read).

The code has multiple passes through plp[i] getting ther qualities and
comparing against conf->min_baseQ.  This is done for printing the
depth, which sequence bases to display, as well as obviously the
quality values.  All 3 of these are now computed in a single step,
putting the values into kstrings.

We still have additional excess loops if we ask for the optional
columns, but that's not the default output and can be dealt with at a
later stage.

Also remove some of the excess seq_nt16_table and seq_nt_str back and
forth, plus specialise for strand so we don't also have to call
toupper and tolower plus detection of the "=" code.

The combined speed up is 20-25% on the BAM files I tested (long and
short read).
@daviesrob daviesrob self-assigned this Feb 22, 2024
@daviesrob

Copy link
Copy Markdown
Member

This generally looks OK, although it would be good to check the various kstring operations for errors, otherwise there is a small risk of silently dropping data.

It would be good to rename the shadowing ns. They're not used in many places, so it wouldn't be too hard.

@daviesrob

Copy link
Copy Markdown
Member

... or even better rename the shadowed one. Just rename it at the top, and the compiler will find any instances that need to be fixed up ...

We now check ksprintf and kputc error codes.  I haven't changed
non-kstring I/O.  We could go through changing all those too, but
traditionally we don't check stdio at the per-putc level and rely on
the error being propagated through to file closure.

Also adjusted the main loop to avoid variable shadowing. (That's
nothing to do with the speed up changes.)
@daviesrob daviesrob merged commit 87ffc8b into samtools:develop Mar 8, 2024
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