Skip to content

perf(ui): use ListView.separated for lazy horizontal breadcrumb rendering#8732

Open
danteboe wants to merge 7 commits into
AppFlowy-IO:mainfrom
danteboe:perf/lazy-breadcrumb-list
Open

perf(ui): use ListView.separated for lazy horizontal breadcrumb rendering#8732
danteboe wants to merge 7 commits into
AppFlowy-IO:mainfrom
danteboe:perf/lazy-breadcrumb-list

Conversation

@danteboe

@danteboe danteboe commented May 16, 2026

Copy link
Copy Markdown

Motivation

  • Previous SingleChildScrollView + Row eagerly built all breadcrumb items causing poor performance in deep trees.

What changed

  • Replaced with ListView.separated horizontal builder keyed by ValueKey(view.id) and lazy separator builder. Items build on demand.

Performance impact

  • Converts eager construction to on-demand builders, significantly reducing initial layout cost and memory pressure.

Testing

  • Manual navigation across deep breadcrumb stacks to confirm rendering and scrolling.

Risk and compatibility

  • Low. Visual parity kept; separators preserved.

Checklist

  • flutter analyze
  • Reviewer: frontend/ui

Summary by Sourcery

Optimize breadcrumb rendering performance and logging/serialization efficiency across Flutter UI and Rust backends, while updating commit lint configuration and cleaning up unused files.

Bug Fixes:

  • Ensure view rename popover has a valid, up-to-date state when opened from the title bar.

Enhancements:

  • Refactor the Flutter view title bar to use a stateful widget with cached breadcrumb widgets and a horizontally scrolling ListView for lazy breadcrumb rendering.
  • Improve ViewTitle popover construction by reusing the latest bloc state and extracting a dedicated builder for the rename popover.
  • Optimize Rust logging by reusing a thread-local buffer for JSON serialization of spans and events to reduce allocations.
  • Avoid intermediate allocations when serializing chat RAG IDs by streaming UUIDs directly into a JSON sequence serializer.
  • Extend commit lint configuration to allow the "perf" commit type for performance-related changes.

Chores:

  • Remove various unused or generated configuration, environment, translation, and build artifact files from the repository.

danteboe added 7 commits May 15, 2026 18:55
- 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>
- Detailed architectural explanation: frequent log serialization previously allocated a new Vec<u8> for each span/event, causing heap churn in high-throughput scenarios.\n- Optimization: introduced a LOG_BUFFER thread-local RefCell<Vec<u8>> reused across serialization calls; buffer is cleared (len=0) but retains capacity between calls. Serialization now writes directly into this buffer and the writer consumes it, avoiding repeated allocations.\n- Impact: reduces heap allocations and GC pressure in hot logging paths; improves throughput for bursty logs.\n\nCo-authored-by: Optimization-Agent <agent@flowy.ai>
…id inline closure allocations

- Architectural explanation: anonymous builder closures allocated during widget rebuilds contribute to transient allocation churn on hot UI paths.\n- Optimization: hoisted the popupBuilder into a _buildRenamePopover method and tracked the latest ViewTitleState in a field so the builder no longer needs an inline anonymous closure.\n- Impact: reduces per-build closure allocations and clarifies lifecycle points for text controller reset logic.\n\nCo-authored-by: Optimization-Agent <agent@flowy.ai>
…rumb rendering

- Detailed architectural explanation: the previous SingleChildScrollView + Row eagerly built all breadcrumb widget instances, causing potentially large widget allocation trees for deep hierarchies.\n- Optimization: replaced with a horizontally scrolling ListView.separated which builds items on demand. Each item uses ValueKey(view.id) to maintain identity. Separators are provided by separatorBuilder to match previous dividers.\n- Impact: converts O(n) eager widget construction to on-demand item builders, reducing initial layout cost and memory pressure when the breadcrumb list is long.\n\nCo-authored-by: Optimization-Agent <agent@flowy.ai>
@CLAassistant

CLAassistant commented May 16, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@sourcery-ai

sourcery-ai Bot commented May 16, 2026

Copy link
Copy Markdown
Contributor

Reviewer's Guide

Refactors the Flutter view title bar breadcrumb rendering to use a lazy horizontal ListView with caching for better performance, introduces safer rename popover state handling, optimizes Rust logging and chat UUID serialization to reduce allocations, and updates commitlint to allow perf-type commits along with minor asset/config cleanups.

Flow diagram for Rust logging with thread local buffer

flowchart LR
  on_event[on_event] --> getbuf[LOG_BUFFER.with]
  getbuf --> clearbuf[clear buffer]
  clearbuf --> serializer[serde_json::Serializer::new]
  serializer --> mapser[serialize_map]
  mapser --> writefields[serialize_fields and extra values]
  writefields --> newline[write_all '\n' to buffer]
  newline --> writer[make_writer.make_writer]
  writer --> emit[write_all buffer to output]
Loading

File-Level Changes

Change Details Files
Refactor view title bar breadcrumbs to render lazily with ListView.separated and cache breadcrumb widgets based on view-related inputs.
  • Convert ViewTitleBar from StatelessWidget to StatefulWidget and introduce _ViewTitleBarState to hold breadcrumb cache state.
  • Cache the list of breadcrumb widgets and invalidate the cache when the main view id or name changes.
  • Replace SingleChildScrollView + Row eager layout with a fixed-height horizontal ListView.separated using a lazy itemBuilder and separatorBuilder.
  • Skip the workspace root in the item builder, preserve deleted-view handling, and key tooltip items by view id for stable identity.
frontend/appflowy_flutter/lib/workspace/presentation/widgets/view_title_bar.dart
Make the view rename popover use the latest ViewTitleBloc state while avoiding stale-state issues when opening the popover.
  • Store the latest ViewTitleState in the ViewTitle widget’s state during Bloc builder execution.
  • Extract the rename popup builder into a dedicated _buildRenamePopover method that uses the cached state when available.
  • Fallback to reading the current bloc state from context if the cached state is not yet initialized, ensuring the text controller is reset consistently.
frontend/appflowy_flutter/lib/workspace/presentation/widgets/view_title_bar.dart
Introduce a reusable thread-local buffer for JSON log formatting to reduce allocations and write log records directly to the writer.
  • Add a LOG_BUFFER thread_local RefCell<Vec> initialized with a fixed capacity to reuse per-thread buffers.
  • Change span serialization to write into the shared buffer, include a trailing newline, and emit directly through make_writer instead of returning a Vec.
  • Update event formatting to reuse the thread-local buffer, remove the intermediate closure and Vec, append newline, and write directly to the writer.
frontend/rust-lib/lib-log/src/layer.rs
Optimize chat table rag_ids serialization from UUIDs to JSON without an intermediate Vec allocation.
  • Add a small helper function to serialize a slice of Uuid into a JSON array using serde’s SerializeSeq directly into a Vec.
  • Use the new helper when constructing ChatTable, keeping metadata serialization unchanged and wrapping the result in Some().
frontend/rust-lib/flowy-ai-pub/src/persistence/chat_sql.rs
Allow perf commit type in commit linting rules.
  • Extend commitlint type-enum configuration to include "perf" alongside existing commit types.
commitlint.config.js
Housekeeping: remove unused or generated files from the repo.
  • Delete an unused Marathi translation JSON file from appflowy_flutter assets.
  • Delete platform build cache, local Rust cargo config, and sqlite .env files that should not be version-controlled.
frontend/appflowy_flutter/assets/translations/mr-IN.json
frontend/appflowy_flutter/macos/build/ios/XCBuildData/PIFCache/project/PROJECT@v11_mod=a7fbf46937053896f73cc7c7ec6baefb_hash=bfdfe7dc352907fc980b868725387e98plugins=1OJSG6M1FOV3XYQCBH7Z29RZ0FPR9XDE1-json
frontend/rust-lib/.cargo/config.toml
frontend/rust-lib/flowy-sqlite/.env

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've left some high level feedback:

  • In ViewTitleBar, _cachedBreadcrumbs is populated but never actually used by the ListView.separated builder (which rebuilds each item from ancestors), so either wire the cache into itemBuilder or drop the cache logic to avoid unnecessary state.
  • The previous _buildLockPageStatus widget that appeared after the breadcrumb row is no longer rendered with the new ListView.separated layout; if this status indicator is still desired, it should be reinserted (e.g., as a trailing item) or the unused helper removed.
  • The new serialization helpers (serialize_rag_ids_from_uuids, logging JSON writers) rely on multiple unwrap/unwrap_or_default calls, which can panic or silently lose data; consider returning a Result and propagating errors (or at least logging them) to keep behavior predictable and robust.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `ViewTitleBar`, `_cachedBreadcrumbs` is populated but never actually used by the `ListView.separated` builder (which rebuilds each item from `ancestors`), so either wire the cache into `itemBuilder` or drop the cache logic to avoid unnecessary state.
- The previous `_buildLockPageStatus` widget that appeared after the breadcrumb row is no longer rendered with the new `ListView.separated` layout; if this status indicator is still desired, it should be reinserted (e.g., as a trailing item) or the unused helper removed.
- The new serialization helpers (`serialize_rag_ids_from_uuids`, logging JSON writers) rely on multiple `unwrap`/`unwrap_or_default` calls, which can panic or silently lose data; consider returning a `Result` and propagating errors (or at least logging them) to keep behavior predictable and robust.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

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.

2 participants