Reduce quick switch layout churn and flatten planar depth transforms
This commit is contained in:
@@ -12,10 +12,12 @@ class ChatPanePresentation extends InheritedWidget {
|
|||||||
super.key,
|
super.key,
|
||||||
required this.peek,
|
required this.peek,
|
||||||
required this.barReveal,
|
required this.barReveal,
|
||||||
|
this.fixedChromeLayout = false,
|
||||||
required super.child,
|
required super.child,
|
||||||
});
|
});
|
||||||
|
|
||||||
final bool peek;
|
final bool peek;
|
||||||
|
final bool fixedChromeLayout;
|
||||||
final Animation<double> barReveal;
|
final Animation<double> barReveal;
|
||||||
|
|
||||||
static ChatPanePresentation? maybeOf(BuildContext context) =>
|
static ChatPanePresentation? maybeOf(BuildContext context) =>
|
||||||
@@ -23,7 +25,9 @@ class ChatPanePresentation extends InheritedWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
bool updateShouldNotify(ChatPanePresentation oldWidget) =>
|
bool updateShouldNotify(ChatPanePresentation oldWidget) =>
|
||||||
peek != oldWidget.peek || barReveal != oldWidget.barReveal;
|
peek != oldWidget.peek ||
|
||||||
|
barReveal != oldWidget.barReveal ||
|
||||||
|
fixedChromeLayout != oldWidget.fixedChromeLayout;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The conversation's bar under a [ChatPanePresentation].
|
/// The conversation's bar under a [ChatPanePresentation].
|
||||||
@@ -60,7 +64,9 @@ class ChatPaneBarReveal extends StatelessWidget {
|
|||||||
ignoring: peek,
|
ignoring: peek,
|
||||||
child: SizeTransition(
|
child: SizeTransition(
|
||||||
alignment: Alignment.topCenter,
|
alignment: Alignment.topCenter,
|
||||||
sizeFactor: reveal,
|
sizeFactor: presentation.fixedChromeLayout
|
||||||
|
? const AlwaysStoppedAnimation(1.0)
|
||||||
|
: reveal,
|
||||||
child: FadeTransition(
|
child: FadeTransition(
|
||||||
opacity: reveal,
|
opacity: reveal,
|
||||||
child: SlideTransition(
|
child: SlideTransition(
|
||||||
|
|||||||
@@ -67,6 +67,7 @@ class ChatMobilePaneViewport extends StatelessWidget {
|
|||||||
required this.peek,
|
required this.peek,
|
||||||
required this.active,
|
required this.active,
|
||||||
required this.barReveal,
|
required this.barReveal,
|
||||||
|
this.fixedChromeLayout = false,
|
||||||
required this.child,
|
required this.child,
|
||||||
required this.onActivate,
|
required this.onActivate,
|
||||||
required this.label,
|
required this.label,
|
||||||
@@ -75,6 +76,7 @@ class ChatMobilePaneViewport extends StatelessWidget {
|
|||||||
|
|
||||||
final bool peek;
|
final bool peek;
|
||||||
final bool active;
|
final bool active;
|
||||||
|
final bool fixedChromeLayout;
|
||||||
|
|
||||||
/// The bar's reveal for this pane's role (see [ChatPanePresentation]).
|
/// The bar's reveal for this pane's role (see [ChatPanePresentation]).
|
||||||
final Animation<double> barReveal;
|
final Animation<double> barReveal;
|
||||||
@@ -103,6 +105,7 @@ class ChatMobilePaneViewport extends StatelessWidget {
|
|||||||
child: ChatPanePresentation(
|
child: ChatPanePresentation(
|
||||||
peek: peek,
|
peek: peek,
|
||||||
barReveal: barReveal,
|
barReveal: barReveal,
|
||||||
|
fixedChromeLayout: fixedChromeLayout,
|
||||||
child: child,
|
child: child,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
import 'package:flutter/widgets.dart';
|
||||||
|
|
||||||
|
/// Keeps the expensive transcript layout at one useful size while its card's
|
||||||
|
/// painted rectangle moves. Resting peek constraints remain the real viewport.
|
||||||
|
class ChatMotionViewport extends StatelessWidget {
|
||||||
|
const ChatMotionViewport({
|
||||||
|
super.key,
|
||||||
|
required this.size,
|
||||||
|
required this.child,
|
||||||
|
});
|
||||||
|
final Size? size;
|
||||||
|
final Widget child;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) => LayoutBuilder(
|
||||||
|
builder: (context, constraints) {
|
||||||
|
final viewport = size ?? constraints.biggest;
|
||||||
|
return ClipRect(
|
||||||
|
child: OverflowBox(
|
||||||
|
alignment: Alignment.topLeft,
|
||||||
|
minWidth: viewport.width,
|
||||||
|
maxWidth: viewport.width,
|
||||||
|
minHeight: viewport.height,
|
||||||
|
maxHeight: viewport.height,
|
||||||
|
child: child,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -259,6 +259,7 @@ class _ChatWorkspaceState extends State<ChatWorkspace>
|
|||||||
peek: peek,
|
peek: peek,
|
||||||
active: active,
|
active: active,
|
||||||
barReveal: _motion.revealFor(pane.id),
|
barReveal: _motion.revealFor(pane.id),
|
||||||
|
fixedChromeLayout: _motion.isAnimating && !_motion.isTape,
|
||||||
label: widget.paneTitle?.call(pane) ?? pane.sessionId,
|
label: widget.paneTitle?.call(pane) ?? pane.sessionId,
|
||||||
paneId: pane.id,
|
paneId: pane.id,
|
||||||
onActivate: () {
|
onActivate: () {
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import 'chat_pane_backdrop.dart';
|
|||||||
import 'chat_pane_switch_motion.dart';
|
import 'chat_pane_switch_motion.dart';
|
||||||
import 'chat_tape_exit.dart';
|
import 'chat_tape_exit.dart';
|
||||||
import 'chat_switch_card.dart';
|
import 'chat_switch_card.dart';
|
||||||
|
import 'chat_motion_viewport.dart';
|
||||||
import 'chat_workspace_controller.dart';
|
import 'chat_workspace_controller.dart';
|
||||||
import 'chat_workspace_divider.dart';
|
import 'chat_workspace_divider.dart';
|
||||||
import 'chat_workspace_geometry.dart';
|
import 'chat_workspace_geometry.dart';
|
||||||
@@ -87,7 +88,12 @@ Widget chatWorkspaceSurface({
|
|||||||
child: ChatSwitchCard(
|
child: ChatSwitchCard(
|
||||||
motion: motion,
|
motion: motion,
|
||||||
outgoing: motion.isRetainedOutgoing(pane.id),
|
outgoing: motion.isRetainedOutgoing(pane.id),
|
||||||
child: child!,
|
child: ChatMotionViewport(
|
||||||
|
size: mobile != null && motion.isAnimating && !motion.isTape
|
||||||
|
? motion.viewportRectFor(pane.id)?.size
|
||||||
|
: null,
|
||||||
|
child: child!,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -18,18 +18,34 @@ class QuickSwitchPose {
|
|||||||
final Offset translation;
|
final Offset translation;
|
||||||
final double scale, rotationX, rotationY, rotationZ, depth, opacity, shadow;
|
final double scale, rotationX, rotationY, rotationZ, depth, opacity, shadow;
|
||||||
|
|
||||||
Matrix4 transform(Size size) => Matrix4.identity()
|
Matrix4 transform(Size size) {
|
||||||
..setEntry(3, 2, rotationX != 0 || rotationY != 0 || depth != 0 ? .0012 : 0)
|
// A flat card at constant depth projects to a uniform 2D scale. Keep it
|
||||||
..translateByDouble(
|
// affine so backdrop filters do not enter the renderer's 3D path.
|
||||||
translation.dx * size.width,
|
if (rotationX == 0 && rotationY == 0) {
|
||||||
translation.dy * size.height,
|
final projection = 1 / (1 + .0012 * depth);
|
||||||
depth,
|
return Matrix4.identity()
|
||||||
1,
|
..translateByDouble(
|
||||||
)
|
translation.dx * size.width * projection,
|
||||||
..rotateX(rotationX)
|
translation.dy * size.height * projection,
|
||||||
..rotateY(rotationY)
|
0,
|
||||||
..rotateZ(rotationZ)
|
1,
|
||||||
..scaleByDouble(scale, scale, scale, 1);
|
)
|
||||||
|
..rotateZ(rotationZ)
|
||||||
|
..scaleByDouble(scale * projection, scale * projection, 1, 1);
|
||||||
|
}
|
||||||
|
return Matrix4.identity()
|
||||||
|
..setEntry(3, 2, .0012)
|
||||||
|
..translateByDouble(
|
||||||
|
translation.dx * size.width,
|
||||||
|
translation.dy * size.height,
|
||||||
|
depth,
|
||||||
|
1,
|
||||||
|
)
|
||||||
|
..rotateX(rotationX)
|
||||||
|
..rotateY(rotationY)
|
||||||
|
..rotateZ(rotationZ)
|
||||||
|
..scaleByDouble(scale, scale, scale, 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool quickSwitchOutgoingOnTop(QuickSwitchAnimation style, double progress) =>
|
bool quickSwitchOutgoingOnTop(QuickSwitchAnimation style, double progress) =>
|
||||||
|
|||||||
@@ -0,0 +1,71 @@
|
|||||||
|
# Mobile quick-switch frame profile
|
||||||
|
|
||||||
|
Measured 2026-11-07 using the real full-app fixture, rich 120-message chats,
|
||||||
|
560×1000 touch input, Flutter profile web build with source maps, private
|
||||||
|
headless Chrome, CanvasKit software rasterization, semantics enabled and no CPU
|
||||||
|
throttle. Never used production chats. No Android device was connected. The
|
||||||
|
managed Pipelines_Fold_A .ini points to a missing .avd directory; no emulator
|
||||||
|
was created and the personal Fold was not used. These are comparative browser
|
||||||
|
measurements, not Android hardware FPS claims.
|
||||||
|
|
||||||
|
## Diagnosis and bounded changes
|
||||||
|
|
||||||
|
Each animation tick resized two real transcript viewports and changed the
|
||||||
|
header/composer occupied height. This repeatedly laid out expensive chat
|
||||||
|
content. The previous Card stack's perspective/hinge motion also had much
|
||||||
|
higher software-raster cost than a flat swap. CPU samples were dominated by
|
||||||
|
CanvasKit raster/surface work; eliminating layout alone cannot remove that tail.
|
||||||
|
|
||||||
|
Non-tape exchanges now lay out the incoming transcript at its destination
|
||||||
|
viewport and retain the outgoing source viewport until settling. ClipRect and
|
||||||
|
OverflowBox animate only the painted rectangle; the actual resting preview
|
||||||
|
still receives its real small constraints, so its final content remains
|
||||||
|
reachable. Chrome keeps its occupied layout height during the exchange while
|
||||||
|
its existing fade/slide still paints. The final layout applies once at rest.
|
||||||
|
Tape remains unchanged because its continuous loop uses a separate picture.
|
||||||
|
|
||||||
|
A flat card at constant depth projects to a uniform 2D scale. The shared pose
|
||||||
|
helper now uses the mathematically equivalent affine transform for these cards,
|
||||||
|
while actual Flip/Rolodex rotations keep perspective. Regression verifies the
|
||||||
|
same projected points instead of requiring an unnecessary perspective matrix.
|
||||||
|
|
||||||
|
## Quiet before/after confirmation
|
||||||
|
|
||||||
|
Two repetitions × six warmed touch switches per build, same fixture and 850 ms
|
||||||
|
cadence. Root paused other builds/tests/captures for this comparison. Before is
|
||||||
|
the new true Card deck library without the performance patch; after includes
|
||||||
|
fixed viewports/chrome and affine flat-depth projection. Values below are the
|
||||||
|
benchmark's upper median across the two repetitions.
|
||||||
|
|
||||||
|
| Metric | Before | After |
|
||||||
|
| --- | ---: | ---: |
|
||||||
|
| Flutter build p50 | 8.6 ms | 1.6 ms |
|
||||||
|
| Flutter build sum | 902.9 ms | 531.1 ms |
|
||||||
|
| Total frame p50 | 41.8 ms | 32.9 ms |
|
||||||
|
| Flutter frames recorded | 94 | 115 |
|
||||||
|
| Browser rAF interval p95 | 66.7 ms | 50.1 ms |
|
||||||
|
| Long tasks (>50 ms) | 35 | 16 |
|
||||||
|
| Raster p95 | 47.6 ms | 50.9 ms |
|
||||||
|
| Total frame p95 | 65.7 ms | 68.2 ms |
|
||||||
|
|
||||||
|
Typical build cost and cadence improved, but raster p95 and total-frame p95
|
||||||
|
**did not improve**. This does not establish 60 FPS or eliminate Android jank.
|
||||||
|
The remaining renderer/filter cost needs a real authorized Android device to
|
||||||
|
characterize accurately. Browser rAF p50 includes idle gaps and should not be
|
||||||
|
used as the animation FPS.
|
||||||
|
|
||||||
|
Reports, raw Flutter timings, V8 CPU samples and rAF/long-task arrays:
|
||||||
|
- /tmp/mobile-motion-quiet-before/report.json
|
||||||
|
- /tmp/mobile-motion-quiet-after/report.json
|
||||||
|
- Per repetition: run-N.cpuprofile, run-N-cpu.json, run-N-frames.json.
|
||||||
|
|
||||||
|
Exploratory three-repeat baseline (overlapped other development work, so not a
|
||||||
|
strict quiet comparison): Tape total p95 69.9 ms; Swap 45.3 ms; old Card stack
|
||||||
|
88.2 ms with raster p95 75.5 ms. New Card deck before this patch had total p95
|
||||||
|
64.8 ms/raster p95 49.6 ms. The shape change itself therefore helps, but the
|
||||||
|
quiet pair above is the defensible comparison for the performance patch.
|
||||||
|
|
||||||
|
Tests cover no repeated child-constraint layout as painted height changes,
|
||||||
|
fixed occupied chrome during a fade, actual resting peek height, retained
|
||||||
|
chat drafts for every style and equivalent affine projection. Integration
|
||||||
|
browser review remains with the parent task.
|
||||||
@@ -0,0 +1,91 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:pipelines_app/features/chat/conversation/chat_pane_presentation.dart';
|
||||||
|
import 'package:pipelines_app/features/chat/workspace/chat_motion_viewport.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
testWidgets('paint resizing does not repeatedly lay out the transcript', (
|
||||||
|
tester,
|
||||||
|
) async {
|
||||||
|
var layouts = 0;
|
||||||
|
var height = 600.0;
|
||||||
|
Size? fixed = const Size(300, 600);
|
||||||
|
late StateSetter update;
|
||||||
|
final transcript = LayoutBuilder(
|
||||||
|
builder: (context, constraints) {
|
||||||
|
layouts++;
|
||||||
|
return SizedBox(
|
||||||
|
key: const Key('transcript'),
|
||||||
|
width: constraints.maxWidth,
|
||||||
|
height: constraints.maxHeight,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
await tester.pumpWidget(
|
||||||
|
MaterialApp(
|
||||||
|
home: StatefulBuilder(
|
||||||
|
builder: (context, setState) {
|
||||||
|
update = setState;
|
||||||
|
return Align(
|
||||||
|
alignment: Alignment.topLeft,
|
||||||
|
child: SizedBox(
|
||||||
|
width: 300,
|
||||||
|
height: height,
|
||||||
|
child: ChatMotionViewport(size: fixed, child: transcript),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
final initial = layouts;
|
||||||
|
for (final next in [480.0, 360.0, 180.0]) {
|
||||||
|
update(() => height = next);
|
||||||
|
await tester.pump();
|
||||||
|
expect(tester.getSize(find.byKey(const Key('transcript'))).height, 600);
|
||||||
|
}
|
||||||
|
expect(layouts, initial);
|
||||||
|
update(() => fixed = null);
|
||||||
|
await tester.pump();
|
||||||
|
expect(tester.getSize(find.byKey(const Key('transcript'))).height, 180);
|
||||||
|
expect(layouts, initial + 1);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('chrome can fade without changing its occupied layout height', (
|
||||||
|
tester,
|
||||||
|
) async {
|
||||||
|
tester.platformDispatcher.accessibilityFeaturesTestValue =
|
||||||
|
const FakeAccessibilityFeatures(disableAnimations: false);
|
||||||
|
addTearDown(tester.platformDispatcher.clearAccessibilityFeaturesTestValue);
|
||||||
|
final reveal = AnimationController(
|
||||||
|
vsync: tester,
|
||||||
|
duration: const Duration(milliseconds: 200),
|
||||||
|
);
|
||||||
|
await tester.pumpWidget(
|
||||||
|
MaterialApp(
|
||||||
|
home: Align(
|
||||||
|
alignment: Alignment.topLeft,
|
||||||
|
child: ChatPanePresentation(
|
||||||
|
peek: false,
|
||||||
|
fixedChromeLayout: true,
|
||||||
|
barReveal: reveal,
|
||||||
|
child: ChatPaneBarReveal(
|
||||||
|
bar: const SizedBox(width: 100, height: 48),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
final bar = find.byType(ChatPaneBarReveal);
|
||||||
|
expect(tester.getSize(bar).height, 48);
|
||||||
|
reveal.forward();
|
||||||
|
await tester.pump();
|
||||||
|
await tester.pump(const Duration(milliseconds: 60));
|
||||||
|
expect(reveal.value, inExclusiveRange(0, 1));
|
||||||
|
expect(tester.getSize(bar).height, 48);
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
expect(tester.getSize(bar).height, 48);
|
||||||
|
await tester.pumpWidget(const SizedBox());
|
||||||
|
reveal.dispose();
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -75,6 +75,16 @@ void main() {
|
|||||||
controller.activate(a);
|
controller.activate(a);
|
||||||
await tester.pump();
|
await tester.pump();
|
||||||
await tester.pump(const Duration(milliseconds: 140));
|
await tester.pump(const Duration(milliseconds: 140));
|
||||||
|
// Card paint rectangles vary, but transcripts keep their useful full
|
||||||
|
// viewport until settling to the real small preview once.
|
||||||
|
expect(
|
||||||
|
tester.getSize(find.byKey(const ValueKey('a'))).height,
|
||||||
|
closeTo((800 - 6) * .8, .01),
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
tester.getSize(find.byKey(const ValueKey('b'))).height,
|
||||||
|
closeTo((800 - 6) * .8, .01),
|
||||||
|
);
|
||||||
expect(find.byKey(const ValueKey('chat-tape-exit')), findsNothing);
|
expect(find.byKey(const ValueKey('chat-tape-exit')), findsNothing);
|
||||||
expect(find.byKey(const ValueKey('chat-swap-exit')), findsNothing);
|
expect(find.byKey(const ValueKey('chat-swap-exit')), findsNothing);
|
||||||
Stack surface() => tester.widget<Stack>(
|
Stack surface() => tester.widget<Stack>(
|
||||||
@@ -94,8 +104,6 @@ void main() {
|
|||||||
expect(
|
expect(
|
||||||
card.transform.entry(3, 2) != 0,
|
card.transform.entry(3, 2) != 0,
|
||||||
{
|
{
|
||||||
QuickSwitchAnimation.cardStack,
|
|
||||||
QuickSwitchAnimation.deckSlide,
|
|
||||||
QuickSwitchAnimation.flip,
|
QuickSwitchAnimation.flip,
|
||||||
QuickSwitchAnimation.rolodex,
|
QuickSwitchAnimation.rolodex,
|
||||||
}.contains(style),
|
}.contains(style),
|
||||||
@@ -116,6 +124,10 @@ void main() {
|
|||||||
expect(before.controller.text, 'Keep my draft');
|
expect(before.controller.text, 'Keep my draft');
|
||||||
expect(tester.getRect(rect(a)).top, 0);
|
expect(tester.getRect(rect(a)).top, 0);
|
||||||
expect(tester.getRect(rect(b)).top, _peekTop);
|
expect(tester.getRect(rect(b)).top, _peekTop);
|
||||||
|
expect(
|
||||||
|
tester.getSize(find.byKey(const ValueKey('b'))).height,
|
||||||
|
closeTo((800 - 6) * .2, .01),
|
||||||
|
);
|
||||||
expect(find.byKey(const ValueKey('chat-swap-exit')), findsNothing);
|
expect(find.byKey(const ValueKey('chat-swap-exit')), findsNothing);
|
||||||
await tester.pumpWidget(const SizedBox());
|
await tester.pumpWidget(const SizedBox());
|
||||||
controller.dispose();
|
controller.dispose();
|
||||||
|
|||||||
@@ -46,6 +46,37 @@ void main() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test(
|
||||||
|
'flat deck depth keeps the same projection on the cheaper affine path',
|
||||||
|
() {
|
||||||
|
for (final depth in [-18.0, 0.0, 18.0]) {
|
||||||
|
final pose = QuickSwitchPose(
|
||||||
|
translation: const Offset(-.7, .04),
|
||||||
|
rotationZ: -.04,
|
||||||
|
depth: depth,
|
||||||
|
scale: .96,
|
||||||
|
);
|
||||||
|
final original = Matrix4.identity()
|
||||||
|
..setEntry(3, 2, .0012)
|
||||||
|
..translateByDouble(-.7 * 560, .04 * 635, depth, 1)
|
||||||
|
..rotateZ(-.04)
|
||||||
|
..scaleByDouble(.96, .96, .96, 1);
|
||||||
|
final affine = pose.transform(full.size);
|
||||||
|
expect(affine.entry(3, 2), 0);
|
||||||
|
for (final point in [
|
||||||
|
Offset.zero,
|
||||||
|
const Offset(560, 635),
|
||||||
|
const Offset(280, 320),
|
||||||
|
]) {
|
||||||
|
final expected = MatrixUtils.transformPoint(original, point);
|
||||||
|
final actual = MatrixUtils.transformPoint(affine, point);
|
||||||
|
expect(actual.dx, closeTo(expected.dx, .000001));
|
||||||
|
expect(actual.dy, closeTo(expected.dy, .000001));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
test('all choices have finite bounded geometry throughout a transition', () {
|
test('all choices have finite bounded geometry throughout a transition', () {
|
||||||
for (final style in QuickSwitchAnimation.values) {
|
for (final style in QuickSwitchAnimation.values) {
|
||||||
for (final outgoing in [true, false]) {
|
for (final outgoing in [true, false]) {
|
||||||
|
|||||||
Reference in New Issue
Block a user