Skip to content

perf(fst): borrow the grammar in apply instead of cloning it - #90

Open
Alex-Wengg wants to merge 1 commit into
mainfrom
perf/fst-no-grammar-clone
Open

Alex-Wengg wants to merge 1 commit into
mainfrom
perf/fst-no-grammar-clone

Conversation

@Alex-Wengg

Copy link
Copy Markdown
Member

engine::apply composed the input acceptor with fst.clone(), deep-copying the whole grammar FST on every call. Verbalize runs once per token, and es verbalize is the largest bundled grammar, so Spanish paid for several MB of copying per token. rustfst::compose accepts any Borrow<F2> + Clone, so this passes the reference instead.

FLEURS test transcripts, release build, M5 Pro:

Before After
es (281 sentences) 115.8 ms/sentence, 208 MB peak 5.2 ms/sentence, 133 MB
fr (262 sentences) 12.1 ms/sentence, 61 MB peak 7.3 ms/sentence, 44 MB
  • Output is byte-identical on both sets; cargo test --release --features fst-engine passes (parity suite included).
  • Found through FluidAudio's Kokoro Spanish frontend (FluidAudio #950), which normalizes every utterance.

🤖 Generated with Claude Code

engine::apply composed `byte_acceptor(input)` with `fst.clone()`, which
deep-copied the whole grammar FST on every call. apply runs once for
classify and once per token (per field permutation) for verbalize, and
es verbalize is the largest bundled grammar (1.6 MB gzipped). rustfst's
compose takes any Borrow<F2> + Clone, so pass the reference.

FluidAudio's Kokoro Spanish TTS frontend runs this on every utterance
(FluidAudio #926/#950). FLEURS test transcripts, release, M5 Pro:

  es  115.8 → 5.2 ms/sentence (281), peak RSS 208 → 133 MB
  fr   12.1 → 7.3 ms/sentence (262), peak RSS  61 →  44 MB

Output is byte-identical on both sets, and the fst_parity suite passes.
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