perf: build unshown run-detail tabs after the route transition; interaction bench
FadeThroughStack(lazy: true) builds only the shown page first and the rest one per frame once no animation runs. Opening a run detail no longer lays out Timeline, Artifacts and Changes offstage during the route transition (transition build 62-103 ms -> 38-59 ms); first tab switches are unchanged. Adds tool/perf/interaction_bench.mjs (FrameTiming per interaction over the full-app fixture, CPU profiles mapped to Dart files), fixture options for hits/chats/graph, and notes/perf-round3.md with the survey.
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import 'package:flutter/scheduler.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
import 'motion.dart';
|
||||
@@ -7,15 +8,23 @@ import 'motion.dart';
|
||||
/// Unlike [AnimatedSwitcher], this never removes a page after it has been
|
||||
/// visited, so scroll positions, controllers and local state remain owned by
|
||||
/// their original element tree.
|
||||
///
|
||||
/// With [lazy], the stack first builds only the page on screen. It builds
|
||||
/// the others one per frame once no animation is running, or at once when one
|
||||
/// is shown first. Opening a page with several tabs then builds one tab during
|
||||
/// its route transition, and the first switch to another tab still usually
|
||||
/// finds it built.
|
||||
class FadeThroughStack extends StatefulWidget {
|
||||
const FadeThroughStack({
|
||||
super.key,
|
||||
required this.index,
|
||||
required this.children,
|
||||
this.lazy = false,
|
||||
});
|
||||
|
||||
final int index;
|
||||
final List<Widget> children;
|
||||
final bool lazy;
|
||||
|
||||
@override
|
||||
State<FadeThroughStack> createState() => _FadeThroughStackState();
|
||||
@@ -30,11 +39,35 @@ class _FadeThroughStackState extends State<FadeThroughStack>
|
||||
late int _visibleIndex = widget.index;
|
||||
int? _outgoingIndex;
|
||||
|
||||
/// The pages built so far; with [FadeThroughStack.lazy], the rest are not
|
||||
/// built yet.
|
||||
late final Set<int> _visited = {widget.index};
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_controller.value = 1;
|
||||
_controller.addStatusListener(_statusChanged);
|
||||
if (widget.lazy) _buildNextWhenIdle();
|
||||
}
|
||||
|
||||
/// After each frame: once no animation is running (no transient frame
|
||||
/// callbacks, such as a route transition's), builds the first page not
|
||||
/// built yet, one per frame, until every page is built.
|
||||
void _buildNextWhenIdle() {
|
||||
SchedulerBinding.instance.addPostFrameCallback((_) {
|
||||
if (!mounted) return;
|
||||
final count = widget.children.length;
|
||||
final next = [
|
||||
for (var i = 0; i < count; i++)
|
||||
if (!_visited.contains(i)) i,
|
||||
];
|
||||
if (next.isEmpty) return;
|
||||
if (SchedulerBinding.instance.transientCallbackCount == 0) {
|
||||
setState(() => _visited.add(next.first));
|
||||
}
|
||||
_buildNextWhenIdle();
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -74,6 +107,7 @@ class _FadeThroughStackState extends State<FadeThroughStack>
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final reduced = Motion.of(context, Motion.tabFadeThrough) == Duration.zero;
|
||||
_visited.add(widget.index);
|
||||
if (reduced) {
|
||||
_outgoingIndex = null;
|
||||
_visibleIndex = widget.index;
|
||||
@@ -129,7 +163,12 @@ class _FadeThroughStackState extends State<FadeThroughStack>
|
||||
excluding: !active,
|
||||
child: Transform.scale(
|
||||
scale: scale,
|
||||
child: Opacity(opacity: opacity, child: widget.children[index]),
|
||||
child: Opacity(
|
||||
opacity: opacity,
|
||||
child: !widget.lazy || _visited.contains(index)
|
||||
? widget.children[index]
|
||||
: const SizedBox.shrink(),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user