perf(fst): borrow the grammar in apply instead of cloning it - #90
Open
Alex-Wengg wants to merge 1 commit into
Open
Alex-Wengg wants to merge 1 commit into
Alex-Wengg wants to merge 1 commit into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
engine::applycomposed the input acceptor withfst.clone(), deep-copying the whole grammar FST on every call. Verbalize runs once per token, andesverbalize is the largest bundled grammar, so Spanish paid for several MB of copying per token.rustfst::composeaccepts anyBorrow<F2> + Clone, so this passes the reference instead.FLEURS test transcripts, release build, M5 Pro:
cargo test --release --features fst-enginepasses (parity suite included).🤖 Generated with Claude Code