diff --git a/app/lib/features/chat/conversation/chat_pane_presentation.dart b/app/lib/features/chat/conversation/chat_pane_presentation.dart index 9150c8f3..52a335d9 100644 --- a/app/lib/features/chat/conversation/chat_pane_presentation.dart +++ b/app/lib/features/chat/conversation/chat_pane_presentation.dart @@ -12,10 +12,12 @@ class ChatPanePresentation extends InheritedWidget { super.key, required this.peek, required this.barReveal, + this.fixedChromeLayout = false, required super.child, }); final bool peek; + final bool fixedChromeLayout; final Animation barReveal; static ChatPanePresentation? maybeOf(BuildContext context) => @@ -23,7 +25,9 @@ class ChatPanePresentation extends InheritedWidget { @override 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]. @@ -60,7 +64,9 @@ class ChatPaneBarReveal extends StatelessWidget { ignoring: peek, child: SizeTransition( alignment: Alignment.topCenter, - sizeFactor: reveal, + sizeFactor: presentation.fixedChromeLayout + ? const AlwaysStoppedAnimation(1.0) + : reveal, child: FadeTransition( opacity: reveal, child: SlideTransition( diff --git a/app/lib/features/chat/workspace/chat_mobile_panes.dart b/app/lib/features/chat/workspace/chat_mobile_panes.dart index f6961554..e6439428 100644 --- a/app/lib/features/chat/workspace/chat_mobile_panes.dart +++ b/app/lib/features/chat/workspace/chat_mobile_panes.dart @@ -67,6 +67,7 @@ class ChatMobilePaneViewport extends StatelessWidget { required this.peek, required this.active, required this.barReveal, + this.fixedChromeLayout = false, required this.child, required this.onActivate, required this.label, @@ -75,6 +76,7 @@ class ChatMobilePaneViewport extends StatelessWidget { final bool peek; final bool active; + final bool fixedChromeLayout; /// The bar's reveal for this pane's role (see [ChatPanePresentation]). final Animation barReveal; @@ -103,6 +105,7 @@ class ChatMobilePaneViewport extends StatelessWidget { child: ChatPanePresentation( peek: peek, barReveal: barReveal, + fixedChromeLayout: fixedChromeLayout, child: child, ), ), diff --git a/app/lib/features/chat/workspace/chat_motion_viewport.dart b/app/lib/features/chat/workspace/chat_motion_viewport.dart new file mode 100644 index 00000000..39c4be2d --- /dev/null +++ b/app/lib/features/chat/workspace/chat_motion_viewport.dart @@ -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, + ), + ); + }, + ); +} diff --git a/app/lib/features/chat/workspace/chat_workspace.dart b/app/lib/features/chat/workspace/chat_workspace.dart index d5878cb1..38b9865a 100644 --- a/app/lib/features/chat/workspace/chat_workspace.dart +++ b/app/lib/features/chat/workspace/chat_workspace.dart @@ -259,6 +259,7 @@ class _ChatWorkspaceState extends State peek: peek, active: active, barReveal: _motion.revealFor(pane.id), + fixedChromeLayout: _motion.isAnimating && !_motion.isTape, label: widget.paneTitle?.call(pane) ?? pane.sessionId, paneId: pane.id, onActivate: () { diff --git a/app/lib/features/chat/workspace/chat_workspace_surface.dart b/app/lib/features/chat/workspace/chat_workspace_surface.dart index 33a50ea0..3670d137 100644 --- a/app/lib/features/chat/workspace/chat_workspace_surface.dart +++ b/app/lib/features/chat/workspace/chat_workspace_surface.dart @@ -7,6 +7,7 @@ import 'chat_pane_backdrop.dart'; import 'chat_pane_switch_motion.dart'; import 'chat_tape_exit.dart'; import 'chat_switch_card.dart'; +import 'chat_motion_viewport.dart'; import 'chat_workspace_controller.dart'; import 'chat_workspace_divider.dart'; import 'chat_workspace_geometry.dart'; @@ -87,7 +88,12 @@ Widget chatWorkspaceSurface({ child: ChatSwitchCard( motion: motion, outgoing: motion.isRetainedOutgoing(pane.id), - child: child!, + child: ChatMotionViewport( + size: mobile != null && motion.isAnimating && !motion.isTape + ? motion.viewportRectFor(pane.id)?.size + : null, + child: child!, + ), ), ), ), diff --git a/app/lib/ui/motion/quick_switch_effect.dart b/app/lib/ui/motion/quick_switch_effect.dart index 2508f782..288cef5b 100644 --- a/app/lib/ui/motion/quick_switch_effect.dart +++ b/app/lib/ui/motion/quick_switch_effect.dart @@ -18,18 +18,34 @@ class QuickSwitchPose { final Offset translation; final double scale, rotationX, rotationY, rotationZ, depth, opacity, shadow; - Matrix4 transform(Size size) => Matrix4.identity() - ..setEntry(3, 2, rotationX != 0 || rotationY != 0 || depth != 0 ? .0012 : 0) - ..translateByDouble( - translation.dx * size.width, - translation.dy * size.height, - depth, - 1, - ) - ..rotateX(rotationX) - ..rotateY(rotationY) - ..rotateZ(rotationZ) - ..scaleByDouble(scale, scale, scale, 1); + Matrix4 transform(Size size) { + // A flat card at constant depth projects to a uniform 2D scale. Keep it + // affine so backdrop filters do not enter the renderer's 3D path. + if (rotationX == 0 && rotationY == 0) { + final projection = 1 / (1 + .0012 * depth); + return Matrix4.identity() + ..translateByDouble( + translation.dx * size.width * projection, + translation.dy * size.height * projection, + 0, + 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) => diff --git a/app/notes/mobile-quick-switch-profile.md b/app/notes/mobile-quick-switch-profile.md new file mode 100644 index 00000000..8674a280 --- /dev/null +++ b/app/notes/mobile-quick-switch-profile.md @@ -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. diff --git a/app/test/features/chat/workspace/chat_motion_viewport_test.dart b/app/test/features/chat/workspace/chat_motion_viewport_test.dart new file mode 100644 index 00000000..6f7b0542 --- /dev/null +++ b/app/test/features/chat/workspace/chat_motion_viewport_test.dart @@ -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(); + }); +} diff --git a/app/test/features/chat/workspace/chat_switch_styles_test.dart b/app/test/features/chat/workspace/chat_switch_styles_test.dart index 7e4d23d0..477608ce 100644 --- a/app/test/features/chat/workspace/chat_switch_styles_test.dart +++ b/app/test/features/chat/workspace/chat_switch_styles_test.dart @@ -75,6 +75,16 @@ void main() { controller.activate(a); await tester.pump(); 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-swap-exit')), findsNothing); Stack surface() => tester.widget( @@ -94,8 +104,6 @@ void main() { expect( card.transform.entry(3, 2) != 0, { - QuickSwitchAnimation.cardStack, - QuickSwitchAnimation.deckSlide, QuickSwitchAnimation.flip, QuickSwitchAnimation.rolodex, }.contains(style), @@ -116,6 +124,10 @@ void main() { expect(before.controller.text, 'Keep my draft'); expect(tester.getRect(rect(a)).top, 0); 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); await tester.pumpWidget(const SizedBox()); controller.dispose(); diff --git a/app/test/ui/motion/quick_switch_effect_test.dart b/app/test/ui/motion/quick_switch_effect_test.dart index 6181bf5d..246574d7 100644 --- a/app/test/ui/motion/quick_switch_effect_test.dart +++ b/app/test/ui/motion/quick_switch_effect_test.dart @@ -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', () { for (final style in QuickSwitchAnimation.values) { for (final outgoing in [true, false]) {