Skip to content

perf: three micro-optimizations for render performance and state management#172

Merged
X-Wei merged 4 commits into
X-Wei:masterfrom
5ergioC:micro-optimizations
May 24, 2026
Merged

perf: three micro-optimizations for render performance and state management#172
X-Wei merged 4 commits into
X-Wei:masterfrom
5ergioC:micro-optimizations

Conversation

@5ergioC

@5ergioC 5ergioC commented May 15, 2026

Copy link
Copy Markdown
Contributor

Context

This PR is part of an academic performance analysis of Flutter Catalog conducted
for a mobile development course. If you have any questions about the testing
methodology or the profiling results, feel free to reach out.

Summary

Three micro-optimizations identified through performance profiling on Android 13
(Pixel 6 emulator, Flutter profile mode). No demo behavior or educational content
was changed. Changes are confined to three files.

Before/after results from adb shell dumpsys gfxinfo:

Metric Before After Delta
Median frame time (p50) 81 ms 53 ms -35%
Worst-case frame time (p99) 500 ms 350 ms -30%
Slow draw commands 61 47 -23%

Changes

1. lib/routes/aiml_groq_ex.dart

MyMessageBubbleTile.build() was constructing EdgeInsets, BoxDecoration and
BorderRadius objects inline on every call. Since the chat list rebuilds on every
incoming token, this caused repeated heap allocations of identical objects. Extracted
seven static const fields. The build() method now produces zero new allocations
per rebuild cycle.

2. lib/home_page.dart

Every tab switch triggered a full repaint traversal of all IndexedStack children,
including tabs whose content had not changed. Added a RepaintBoundary wrapping
each of the four ListView children. Each tab subtree is now promoted to its own
compositing layer and the Raster thread reuses the cached bitmap on tab switches.
Verified with Flutter's Highlight Repaints tool.

3. lib/routes/networking_rest_api_fetch_ex.dart

_httpGet() was calling setState() four times per HTTP cycle, rebuilding the
entire widget tree including stable TextField widgets. Replaced with three
ValueNotifier fields and ValueListenableBuilder wrappers so only the affected
widget rebuilds on each state change. All notifiers are disposed correctly. This
also makes the demo a better example of targeted state management.

Testing

flutter analyze passes with no errors on all modified files. App behavior is
identical to the original on all three demo screens. Full profiling data and
before/after screenshots are available if needed.

@5ergioC

5ergioC commented May 24, 2026

Copy link
Copy Markdown
Contributor Author

CupertinoPageTransitionsBuilder was moved from package:flutter/material.dart to package:flutter/cupertino.dart in Flutter 3.44. Adding the missing import fixes the CI flutter analyze failure. These issues exist independently of the changes introduced in this PR and went unnoticed due to version missmatch from most recent version of Flutter.

@X-Wei X-Wei merged commit cf00114 into X-Wei:master May 24, 2026
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