perf: three micro-optimizations for render performance and state management#172
Merged
Conversation
…api_fetch_ex.dart
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. |
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.
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:Changes
1.
lib/routes/aiml_groq_ex.dartMyMessageBubbleTile.build()was constructingEdgeInsets,BoxDecorationandBorderRadiusobjects inline on every call. Since the chat list rebuilds on everyincoming token, this caused repeated heap allocations of identical objects. Extracted
seven static const fields. The
build()method now produces zero new allocationsper rebuild cycle.
2.
lib/home_page.dartEvery tab switch triggered a full repaint traversal of all
IndexedStackchildren,including tabs whose content had not changed. Added a
RepaintBoundarywrappingeach of the four
ListViewchildren. Each tab subtree is now promoted to its owncompositing 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 callingsetState()four times per HTTP cycle, rebuilding theentire widget tree including stable
TextFieldwidgets. Replaced with threeValueNotifierfields andValueListenableBuilderwrappers so only the affectedwidget rebuilds on each state change. All notifiers are disposed correctly. This
also makes the demo a better example of targeted state management.
Testing
flutter analyzepasses with no errors on all modified files. App behavior isidentical to the original on all three demo screens. Full profiling data and
before/after screenshots are available if needed.