Skip to content

Format HMM probabilities without printf in printprob - #22

Closed
kevinmoran1988 wants to merge 1 commit into
TravisWheelerLab:mainfrom
kevinmoran1988:hmmfile-fast-prob-format
Closed

kevinmoran1988 wants to merge 1 commit into
TravisWheelerLab:mainfrom
kevinmoran1988:hmmfile-fast-prob-format

Conversation

@kevinmoran1988

Copy link
Copy Markdown
Contributor

printprob() writes every emission and transition probability as " %8.5f" of -log(p), and glibc's exact-decimal %f path is 8-10% of bathbuild's profile. A float times 1e5 is exact in double, so rint() of that product rounds exactly as printf does, ties to even included. format_prob() builds the digits directly and printprob() writes them with fwrite(). Zero probabilities still print "*" through fprintf, as does anything non-finite or out of range.

Checked exhaustively: all 2,139,095,039 positive floats format byte-identically to glibc's snprintf(" %*.5f").

bathbuild over 5232 dipteraODB12 alignments, serial, 3 runs each, in seconds:

base 230.97 / 232.23 / 229.27
patch 224.54 / 223.97 / 222.84 (1.03x)

Output byte-identical to base on that corpus.

🤖 Generated with Claude Code

bathbuild spends much of its write time in glibc's exact %.5f path.
A float times 1e5 is exact in double, so rint() gives printf's rounding;
format the digits directly and fall back to fprintf otherwise.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@GenevieveKrause

Copy link
Copy Markdown
Collaborator

Thanks for the profiling work here. I'm going to pass on this one — not because anything looks wrong, but because I don't think the benefit is worth the added complexity.

This replaces a single, well-understood fprintf call with a hand-rolled float formatter — manual digit extraction, sign handling, round-to-even via rint(), and a fallback path for cases it doesn't handle. That's meaningfully more code to read, maintain, and reason about in a file that previously just deferred to the standard library. For a 1.03x speedup on bathbuild, I don't think that trade is worth making. If this were a 1.3-1.5x+ win, I'd weigh it differently.

Appreciate you digging into this and sharing the numbers either way.

@kevinmoran1988
kevinmoran1988 deleted the hmmfile-fast-prob-format branch September 29, 2026 20:19
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