A patch holding one Multisampler takes about 57 MB more memory in the Rust engine than the same samples on the same keys played through two Samplers, while it sounds the same and costs little more time. Measured with atmo-render (release build, 48 kHz, 128-frame blocks), sixteen glockenspiel samples held for 2 s of an 8 s render:
| patch | peak and RMS | time | most memory resident |
|---|---|---|---|
| one Multisampler | 3.184, 0.0280 | 0.14 s | 140 MB |
| two Samplers, same keys | 3.184, 0.0280 | 0.09 s | 83 MB |
Why, from the code: the Rust engine builds every pad into every voice copy (crates/engine/src/nodes/sample_pad.rs:12-15), since nothing may be allocated while it renders, and each SamplePad holds its own working state — its BufferSource, its rate and shape params with their values, its stage bus and its panner (sample_pad.rs:212-248) — although a pad the note did not strike answers silence without running a stage (process, sample_pad.rs:465-471). The Multisampler has 128 pads where the Sampler has 16, so every voice copy holds eight times as many. The JS engine builds only the pads a note reaches (withoutDeafPads, src/audio/sample-pads.js), so a browser does not see this.
What should be true #
- A pad that a voice never strikes costs a host running the Rust engine little memory beyond its settings, so a Multisampler costs about what a Sampler does.
- Nothing is allocated while rendering, as now.
- Nothing heard changes: every engine fixture and
atmo-render's output for the patches above stay the same. docs/adr/0008-a-multisampler-is-one-pad-per-key.md's consequence about memory is updated with the new numbers.
Fixed in eaa5693. Voice copies held every pad, all 32 of them, including pads with no sample. A pad with no sample named for it (no fill and no module default) is no longer built in a voice copy, and a shared copy builds no pads. Each pad keeps its place among the module's pads, so choking still cuts the right one. Nothing is allocated while rendering, and every engine fixture and trace is unchanged.
Measured with
atmo-render(release build, 48 kHz, 128-frame blocks), sixteen glockenspiel notes held for 2 s of an 8 s render, twenty keys filled:Both render the same bytes as before (peak 3.184, RMS 0.0280). ADR 0008 has the new numbers.
What this does not do: a pad that has a sample but whose key no note reaches is still built, because a key's range is a setting that can move while the patch plays. A Multisampler with all 128 keys filled still holds as much as eight Samplers.