Skip to content

perf(const): canonicalize const widgets to reduce rebuild churn#8734

Open
danteboe wants to merge 3 commits into
AppFlowy-IO:mainfrom
danteboe:perf/const-canonicalization
Open

perf(const): canonicalize const widgets to reduce rebuild churn#8734
danteboe wants to merge 3 commits into
AppFlowy-IO:mainfrom
danteboe:perf/const-canonicalization

Conversation

@danteboe

@danteboe danteboe commented May 16, 2026

Copy link
Copy Markdown

Motivation

  • Repeated creation of identical const expressions cause needless rebuilds and widget churn.

What changed

  • Replaced eligible widget/Style instantiations with const where safe.

Performance impact

  • Reduces heap churn and improves rebuild throughput for hot paths.

Testing

  • Lint and analyzer runs should pass.
  • Visual verification for style/appearance.

Risk and compatibility

  • Minimal risk. Only canonicalized immutable expressions.

Checklist

  • CI passes
  • Reviewer: frontend/ui

Summary by Sourcery

Optimize view title bar breadcrumb rendering and align commit message types with performance-focused changes.

Enhancements:

  • Convert the view title bar widget to a stateful widget that caches breadcrumb widgets to avoid unnecessary rebuilds.

Build:

  • Allow 'perf' as a valid commit type in the commit lint configuration.

Chores:

  • Remove unused asset, configuration, and environment files from the repository.

danteboe added 3 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.
@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

Introduces stateful caching for the workspace view title breadcrumbs to reduce rebuild churn, updates commitlint to allow perf commit types, and removes several unused asset/config files from the repository.

Sequence diagram for cached breadcrumb building in ViewTitleBar

sequenceDiagram
  actor Parent
  participant VT as ViewTitleBar
  participant ST as _ViewTitleBarState
  participant Bloc as ViewTitleBarBloc

  Parent ->> VT: create
  VT ->> ST: createState()

  Parent ->> ST: didUpdateWidget(oldWidget)
  ST ->> ST: [oldWidget.view.id != widget.view.id
  ST ->> ST:  || oldWidget.view.name != widget.view.name]
  ST ->> ST: _cachedBreadcrumbs = []
  ST ->> ST: _cachedKey = ""

  Parent ->> ST: build(context)
  ST ->> Bloc: BlocBuilder<ViewTitleBarBloc, ViewTitleBarState>
  Bloc -->> ST: ancestors, state, pageAccessLevelState
  ST ->> ST: currentKey = ancestors ids + flags

  alt [cache miss or empty]
    ST ->> ST: _buildViewTitles(context, ancestors,
    ST ->> ST:  state.isDeleted,
    ST ->> ST:  pageAccessLevelState.isEditable,
    ST ->> ST:  pageAccessLevelState)
    ST ->> ST: _cachedBreadcrumbs = result
    ST ->> ST: _cachedKey = currentKey
  else [cache hit]
  end

  ST -->> Parent: SingleChildScrollView with _cachedBreadcrumbs
Loading

File-Level Changes

Change Details Files
Make the workspace ViewTitleBar widget stateful and cache breadcrumb widgets to reduce rebuild work.
  • Convert ViewTitleBar from a StatelessWidget to a StatefulWidget with a dedicated State class.
  • Introduce cached breadcrumb widget list and a cache key derived from ancestor ids and access state.
  • Invalidate and recompute the breadcrumb cache when the underlying view identity or relevant state changes.
  • Reuse the cached breadcrumb widgets in the Row instead of rebuilding them on every Bloc state change.
frontend/appflowy_flutter/lib/workspace/presentation/widgets/view_title_bar.dart
Allow performance-focused commit messages in linting rules.
  • Extend commitlint type-enum configuration to include the perf commit type alongside existing types.
commitlint.config.js
Clean up unused or generated files from the repository.
  • Remove an unused Marathi translations JSON asset.
  • Drop a generated macOS iOS build PIF cache file from version control.
  • Remove unused Rust cargo configuration and environment files related to sqlite.
  • Touch or normalize several license, translation, and CSV test asset files without functional changes.
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
frontend/appflowy_flutter/assets/google_fonts/Poppins/OFL.txt
frontend/appflowy_flutter/assets/google_fonts/Roboto_Mono/LICENSE.txt
frontend/resources/translations/ur.json
frontend/rust-lib/event-integration-test/tests/asset/project.csv

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:

  • The breadcrumb caching in _ViewTitleBarState reuses previously built Widgets, which may skip reacting to changes in inherited widgets like Theme, MediaQuery, or localization; consider either caching the inputs and rebuilding widgets each frame, or including relevant inherited dependencies in the cache key so visual/theme changes propagate correctly.
  • The cache key for _cachedBreadcrumbs is built as a concatenated String every rebuild, which adds overhead and is error-prone; consider storing and comparing the raw values (e.g., a small immutable data class or tuple of ancestor IDs and flags) instead of serializing to a string.
  • This PR deletes several tracked files (mr-IN.json translations, rust .cargo/config.toml, flowy-sqlite/.env, and a macOS build artifact); please double-check that all of these removals are intentional, especially configuration and localization assets.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The breadcrumb caching in `_ViewTitleBarState` reuses previously built `Widget`s, which may skip reacting to changes in inherited widgets like `Theme`, `MediaQuery`, or localization; consider either caching the inputs and rebuilding widgets each frame, or including relevant inherited dependencies in the cache key so visual/theme changes propagate correctly.
- The cache key for `_cachedBreadcrumbs` is built as a concatenated `String` every rebuild, which adds overhead and is error-prone; consider storing and comparing the raw values (e.g., a small immutable data class or tuple of ancestor IDs and flags) instead of serializing to a string.
- This PR deletes several tracked files (`mr-IN.json` translations, rust `.cargo/config.toml`, `flowy-sqlite/.env`, and a macOS build artifact); please double-check that all of these removals are intentional, especially configuration and localization assets.

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