Skip to content

Stop the rescorer falling to its memmap while RAM is free - #88

Merged
RobbinBouwmeester merged 2 commits into
mainfrom
fix/nn-stream-threshold-from-ram
Sep 16, 2026
Merged

RobbinBouwmeester merged 2 commits into
mainfrom
fix/nn-stream-threshold-from-ram

Conversation

@RobbinBouwmeester

Copy link
Copy Markdown
Member

Reported as "rescoring is still very very slow". On the six-file Astral experiment the pooled rescore took 166 minutes for 3,133,636 PSMs × 387 features.

Cause

That matrix decodes to 4.52 GiB, and MUMDIA_NN_STREAM_GB was a fixed 4. So the worker chose its disk-backed memmap — over the line by 13%, on a machine with 96 GiB of RAM and 42 free. The recorded in-memory reference for a comparable pool is about 20 minutes, so the fixed threshold cost roughly .

CLAUDE.md already documented this trap almost exactly: "a 4.31 GB matrix against the 4.00 GB default took the slow path". It had simply never been fixed.

Change

Unset, the threshold is now twice free physical memory, floored at the historical 4 GB so a machine too small to benefit is unaffected.

Greater than 1× on purpose: the memmap is a last resort, not a safety margin.

  • between 1× and 2× free memory the operating system pages, which for this largely sequential access is far cheaper than the memmap's indexed minibatch reads;
  • past that the paging thrashes and the memmap becomes the better of two bad options.

The consequence is deliberate and documented: in that band the rescore relies on the page file, so a machine without one (or with a small fixed one) should set MUMDIA_NN_STREAM_GB explicitly. That override works exactly as before.

machine before after
96 GiB, 41 free (the reporter's) 4.00 GB 82.1 GB
48 GiB, 40 free 4.00 GB 80.0 GB
8 GiB, 1 free 4.00 GB 4.00 GB (floor)

Free memory is read without a new dependencypsutil is not in the rescore environment and is not worth the resolver risk for one number — via GlobalMemoryStatusEx on Windows and MemAvailable on Linux, returning None anywhere else so the caller keeps the fixed default rather than guessing.

A correction to my own diagnosis

I told the reporter the worker was silent about this. It was not — it has always printed the backend and the sizes. That line was lost among the DeepLC blank lines that #84 has since removed. It now additionally reports where the threshold came from, and warns plainly when the slow path was taken for want of memory.

Validation

pytest tests/python85 passed, 8 skipped (two new tests: the multiplier is >1 so the memmap is never preferred over paging, the floor holds, the threshold explains itself, and reading free memory is optional and never fatal). Also passes on a bare interpreter with no ML dependencies. Config reference regenerated for the changed env-var documentation.

🤖 Generated with Claude Code

Reported as "rescoring is still very very slow". On a six-file Astral experiment
the pooled rescore took 166 minutes for 3,133,636 PSMs x 387 features.

Cause: that matrix decodes to 4.52 GiB and MUMDIA_NN_STREAM_GB was a fixed 4, so
the worker chose its disk-backed memmap -- over the line by 13%, on a machine
with 96 GiB of RAM and 42 free. The recorded in-memory reference for a comparable
pool is about 20 minutes, so the fixed threshold cost roughly 9x.

Unset, the threshold is now twice free physical memory, floored at the historical
4 GB so a machine too small to benefit is unaffected. Greater than 1x on purpose:
the memmap is a last resort, not a safety margin. Between 1x and 2x the operating
system pages, which for this largely sequential access is far cheaper than the
memmap's indexed minibatch reads; past that the paging thrashes and the memmap
becomes the better of two bad options. The consequence is deliberate and
documented: in that band the rescore relies on the page file, so a machine
without one should set MUMDIA_NN_STREAM_GB explicitly.

Free memory is read without a new dependency -- psutil is not in the rescore
environment and is not worth the resolver risk for one number -- via
GlobalMemoryStatusEx on Windows and MemAvailable on Linux, returning None
anywhere else so the caller keeps the fixed default rather than guessing.

On the machine that reported this: 4.00 GB -> 82.1 GB, and the 4.52 GiB matrix
stays in RAM.

Also corrected in my own reading of it: the worker was never silent about this.
It has always printed the backend and the sizes; that line was simply lost among
the DeepLC blank lines that #84 removed. It now also reports where the threshold
came from, and says plainly when the slow path was taken for want of memory.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@RobbinBouwmeester
RobbinBouwmeester merged commit 7c63449 into main Sep 16, 2026
12 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