Vec::drain with VecDeque::pop_front for O(1) log pruning across all apps#42
Open
AdityaShome wants to merge 1 commit intomofa-org:mainfrom
Open
Vec::drain with VecDeque::pop_front for O(1) log pruning across all apps#42AdityaShome wants to merge 1 commit intomofa-org:mainfrom
AdityaShome wants to merge 1 commit intomofa-org:mainfrom
Conversation
|
@AdityaShome issue #23 |
Author
|
Hello, my PR #42 is different from #23 as #23 is about DirtyVec::push in mofa-dora-bridge/src/shared_state.rs. |
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.
Problem:
All three apps (
mofa-fm,mofa-debate,mofa-asr) stored log entries in aVec<String>capped at 5,000 entries. When full,Vec::drain(0..excess)removed the oldest shifting all remaining elements left in O(n) time. During active voice chat (logs arriving every 50ms), this caused periodic CPU spikes on the UI thread.Additionally,
mofa-debatehad no pruning at all, allowing unbounded memory growth during long sessions.Fixes: #40
Solution:
Switched from
Vec<String>toVecDeque<String>withpush_back()/pop_front()— O(1) per eviction. Same ring-buffer pattern already used in mofa-metrics/src/store.rs.Changes:
mod.rs(mofa-fm)Vec<String>→VecDeque<String>log_panel.rs(mofa-fm)push→push_back,drain→pop_front+ unit testsaudio_controls.rs(mofa-fm)vec![...]→VecDeque::from(vec![...])mod.rs(mofa-debate)Vec<String>→VecDeque<String>log_panel.rs(mofa-debate)MAX_LOG_ENTRIEScapaudio_controls.rs(mofa-debate)vec![...]→VecDeque::from(vec![...])mod.rs(mofa-asr)Vec<String>→VecDeque<String>log_panel.rs(mofa-asr)push→push_back,drain→pop_frontBenchmark: (200K inserts, release mode)
Vec+ drain(0..excess)VecDeque+pop_front()Testing:
cargo check --workspacepasses, no new warningscargo test -p mofa-fm -- log_panel::tests6/6 pass