perf(rust): stream-serialize rag ids to avoid intermediate Vec allocations#8728
Open
danteboe wants to merge 4 commits into
Open
perf(rust): stream-serialize rag ids to avoid intermediate Vec allocations#8728danteboe wants to merge 4 commits into
danteboe wants to merge 4 commits into
Conversation
- Detailed architectural explanation: the previous StatelessWidget implementation rebuilt breadcrumb widget instances on every parent rebuild, causing repeated allocations of intermediate FlowyTooltip/ViewTitle/FlowySvg widgets and increasing GC churn on UI re-renders.\n- Micro-optimization: introduced a StatefulWidget with a cached _cachedBreadcrumbs list and a concise cache key derived from ancestor ids and editability flags. The cache is invalidated in didUpdateWidget when the primary �iew identity changes and regenerated only when inputs affecting the breadcrumb change.\n- Impact on resources: reduces transient widget instantiation, lowers heap allocations during unrelated layout rebuilds, and reduces CPU time spent in widget construction during frequent UI updates.\n\nCo-authored-by: Optimization-Agent <agent@flowy.ai>
…tions in view_title_bar - Architectural explanation: canonicalizing statically parameterized widgets reduces repeated runtime allocations by enabling the Dart compiler to canonicalize identical widget instances at compile-time.\n- Work performed: reviewed �iew_title_bar.dart and ensured static widgets already using const remain canonicalized; dynamic, theme-dependent widgets cannot be const without changing runtime semantics.\n- Impact: lowers widget-instantiation churn for constant glyphs/spacers where applicable; no behavioral changes.
…intermediate allocations - Detailed architectural explanation: existing code collected UUIDs into a temporary Vec<String> before JSON serialization, causing an extra heap allocation proportional to the number of ids.\n- Optimization: added a streaming serializer serialize_rag_ids_from_uuids that writes the JSON array directly from the Uuid iterator into a byte buffer, avoiding the intermediate Vec<String>.\n- Impact: eliminates the transient allocation for rag id lists, reduces heap churn and shortens peak memory usage during chat persistence operations.\n\nCo-authored-by: Optimization-Agent <agent@flowy.ai>
Contributor
Reviewer's GuideOptimizes RAG ID serialization in the Rust chat persistence layer by streaming JSON encoding to avoid intermediate Vec allocations, adds commitlint support for the File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Contributor
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- In
ViewTitleBar, consider simplifying the cache fields (e.g., droplateand use aconst []initializer for_cachedBreadcrumbs, or make the breadcrumbs cache a separate immutable value object) to reduce mutability complexity and make the widget state slightly clearer. - The
currentKeyfor the breadcrumbs cache is built by string-concatenating all ancestor IDs and flags; you might want to replace this with a cheaper identity (e.g., ancestor length plus last ID and relevant flags, or a dedicated data class) to avoid repeated string allocations on rebuilds. - In
serialize_rag_ids_from_uuids, multipleunwrapcalls (onserialize_seq,serialize_element,end, and UTF-8 conversion) can panic at runtime; consider propagating or handling these errors more defensively, or at least usingexpectwith a clear message or a fall-back path.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `ViewTitleBar`, consider simplifying the cache fields (e.g., drop `late` and use a `const []` initializer for `_cachedBreadcrumbs`, or make the breadcrumbs cache a separate immutable value object) to reduce mutability complexity and make the widget state slightly clearer.
- The `currentKey` for the breadcrumbs cache is built by string-concatenating all ancestor IDs and flags; you might want to replace this with a cheaper identity (e.g., ancestor length plus last ID and relevant flags, or a dedicated data class) to avoid repeated string allocations on rebuilds.
- In `serialize_rag_ids_from_uuids`, multiple `unwrap` calls (on `serialize_seq`, `serialize_element`, `end`, and UTF-8 conversion) can panic at runtime; consider propagating or handling these errors more defensively, or at least using `expect` with a clear message or a fall-back path.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
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.
Motivation
Vec<String>which increases peak memory usage for large lists.What changed
serde_json::Serializer+serialize_seq, writing directly into a byte buffer without allocating the intermediateVec.Performance impact
Testing
Risk and compatibility
Checklist
Summary by Sourcery
Optimize RAG ID serialization and improve UI performance in the view title bar while tightening commit message type validation.
Enhancements:
perfcommit type in commitlint configuration for performance-related changes.Chores: