⚡ Bolt: improve scroll performance and rebuild efficiency#33
⚡ Bolt: improve scroll performance and rebuild efficiency#33
Conversation
Implemented several performance optimizations across the application: 1. Optimized scroll performance in MediaDetailScreen by replacing setState with ListenableBuilder for the fading header, preventing full screen rebuilds on every scroll event. 2. Added itemExtent to horizontal hub lists and skeleton loaders to improve scroll smoothness by skipping child measurement during layout. 3. Adopted modern MediaQuery selectors (sizeOf, paddingOf, devicePixelRatioOf, orientationOf) globally to reduce unnecessary widget rebuilds triggered by unrelated MediaQueryData changes. Co-authored-by: Doezer <11655673+Doezer@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
Summary of ChangesHello @Doezer, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the application's performance by addressing common causes of UI jank and excessive rebuilds. It focuses on improving scroll smoothness in detail screens and horizontal lists, and reducing the overall frequency of widget rebuilds by making Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
The pull request successfully implements several key performance optimizations, including localized scroll rebuilds using ListenableBuilder, explicit itemExtent for lists, and specific MediaQuery selectors. These changes significantly reduce unnecessary widget rebuilds and layout overhead. I have provided a few suggestions to further optimize the scroll-linked header in MediaDetailScreen by using the child parameter of ListenableBuilder and switching from AnimatedOpacity to Opacity for continuous scroll-linked values.
| child: ListenableBuilder( | ||
| listenable: _scrollController, | ||
| builder: (context, child) { | ||
| final offset = _scrollController.hasClients ? _scrollController.offset : 0.0; | ||
| return IgnorePointer( | ||
| ignoring: offset < 50, | ||
| child: AnimatedOpacity( | ||
| opacity: (offset / 100).clamp(0.0, 1.0), | ||
| duration: const Duration(milliseconds: 150), | ||
| child: Container( | ||
| height: MediaQuery.paddingOf(context).top + 58, | ||
| decoration: BoxDecoration( | ||
| gradient: LinearGradient( | ||
| begin: Alignment.topCenter, | ||
| end: Alignment.bottomCenter, | ||
| colors: [ | ||
| Theme.of(context).scaffoldBackgroundColor.withValues(alpha: 0.8), | ||
| Theme.of(context).scaffoldBackgroundColor.withValues(alpha: 0.5), | ||
| Theme.of(context).scaffoldBackgroundColor.withValues(alpha: 0), | ||
| ], | ||
| stops: const [0.0, 0.3, 1.0], | ||
| ), | ||
| ), | ||
| ), | ||
| ), | ||
| ), | ||
| ), | ||
| ); | ||
| }, | ||
| ), |
There was a problem hiding this comment.
While using ListenableBuilder is a great improvement over setState, the current implementation rebuilds the entire sticky top bar (including the Container and its LinearGradient) on every scroll tick.
Additionally, using AnimatedOpacity with a value that changes continuously (based on scroll offset) is inefficient because it triggers a new animation cycle on every frame. For scroll-linked effects, a standard Opacity widget is preferred.
You can further optimize this by passing the static Container as a child to the ListenableBuilder to avoid recreating it on every scroll frame.
child: ListenableBuilder(
listenable: _scrollController,
child: Container(
height: MediaQuery.paddingOf(context).top + 58,
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [
Theme.of(context).scaffoldBackgroundColor.withValues(alpha: 0.8),
Theme.of(context).scaffoldBackgroundColor.withValues(alpha: 0.5),
Theme.of(context).scaffoldBackgroundColor.withValues(alpha: 0),
],
stops: const [0.0, 0.3, 1.0],
),
),
),
builder: (context, child) {
final offset = _scrollController.hasClients ? _scrollController.offset : 0.0;
return IgnorePointer(
ignoring: offset < 50,
child: Opacity(
opacity: (offset / 100).clamp(0.0, 1.0),
child: child,
),
);
},
),
💡 What: Implemented three core performance optimizations: localized scroll rebuilds, explicit item extents for lists, and specific MediaQuery selectors.
🎯 Why: The application suffered from excessive full-screen rebuilds during scrolling and unnecessary rebuilds due to global MediaQuery dependencies. Horizontal lists were also incurring layout overhead by measuring every child.
📊 Impact:
🔬 Measurement: Verified via code review and static analysis. Manual inspection confirms correct implementation of ListenableBuilder and specific MediaQuery getters.
PR created automatically by Jules for task 16877321940720218718 started by @Doezer