Skip to main content

featurize_memo

Function featurize_memo 

Source
pub fn featurize_memo(
    tree: &PatchTree,
    spec: &PhraseSpec,
    memo: &RenderMemo,
    want_audio: bool,
) -> Result<(CachedFeatures, Option<Arc<Audition>>), FeaturizeError>
Expand description

featurize, consulting memo first and populating it on a miss.

want_audio says whether the caller has any use for samples. It is not a hint: with it false this function never converts f64→f32 and never touches the audio tier, so the refinement surrogate — which runs this twice per MH step and discards audio every time — pays for φ and nothing else. Asking for audio you will not play costs a ~565 KB conversion on a miss and keeps a buffer alive on a hit, which is the whole expense the memo exists to remove.

With want_audio, returns the audition buffer when this call rendered it or found it still resident; a hit whose buffer has aged out of the small audio tier yields None, and callers that need one regardless re-derive it with crate::render_playback. The buffer is shared with the memo through an Arc, so producing it allocates once.

Only successes are memoized. A quarantined or uncompilable term is re-attempted on every request, which costs a render — but the trees that repeat are precisely the ones MH has accepted, and an accepted tree vetted by construction. Caching failures would buy a rounding error and require the vet report to survive round-tripping through the memo, where a stale one would be a DESIGN §2.1 gate bypass.