Skip to content

Commit 49e41f3

Browse files
Emanuel4100claude
andcommitted
Smoother Week view, and measure rendering
Flutter 3.47 on Linux draws at a fixed 60 fps (no vsync in the GTK embedder, flutter/flutter#183703), so a 100 Hz monitor shows uneven frames. The app can't fix that, but it no longer adds slow frames: - Swiping weeks updates only the app bar (a ValueNotifier) instead of rebuilding both visible weeks halfway through the swipe. - layoutTile() results are cached: a tile's text measurement isn't redone when nothing about it changed. - Each day column is its own layer, so a hover or splash repaints one day. - The theme no longer forces InkSparkle (a 617 ms shader per tap) on desktop and iPhone; Android keeps it as Flutter's default. - Settings → Developer → Rendering: display rate, fps while animating, build/raster p50/p90/max and frames over budget (FrameStats, also in diagnostics and bug reports). - Linux runner: LECCHECK_UI_THREAD=separate runs Dart off GTK's main thread, to compare. Phone and desktop goldens are unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01JQteV6Ue1SaDcQhPaPy8Sb
1 parent e2694c3 commit 49e41f3

10 files changed

Lines changed: 409 additions & 67 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@
2121
- **Report a problem** (Settings → About): sends a description and, if you leave it on,
2222
diagnostics you can read first; they go privately to the developer, and wait on the
2323
device while offline. After an error, Today offers to report it.
24+
- **Week**: smoother swipes and zoom: changing weeks no longer rebuilds both visible
25+
weeks, tile layouts are measured once, and a tap or hover repaints only its day. On
26+
desktop and iPhone, taps show a plain ripple instead of Android's sparkle effect.
27+
- **Settings → Developer → Rendering**: the display's refresh rate, frames per second while
28+
animating, and frame times, also included in bug reports. On Linux, Flutter draws at
29+
60 fps whatever the monitor's rate (an upstream limit).
2430
- **Sync server**: health checks, and automatic deploys that are tested first, checked
2531
live, and rolled back by themselves if the new version fails. App releases wait until
2632
their server is live.

‎app/lib/app/diagnostics.dart‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import 'package:material_ui/material_ui.dart';
55
import 'package:package_info_plus/package_info_plus.dart';
66

77
import '../core/dev/dev_log.dart';
8+
import '../core/dev/frame_stats.dart';
89
import '../core/notifications/android_device.dart';
910
import '../core/notifications/notification_service.dart';
1011
import '../core/sync/sync_config.dart';
@@ -29,6 +30,11 @@ Future<String> collectDiagnostics(
2930
final notifications = await NotificationService.instance.status();
3031
final log = (await DevLog.read()).trimRight().split('\n');
3132
final android = AppIdiom.isAndroid ? await AndroidDevice.info() : null;
33+
if (!context.mounted) return '';
34+
final view = View.of(context);
35+
final frames = FrameStats.instance.summary(
36+
refreshRate: view.display.refreshRate,
37+
);
3238
final version = await PackageInfo.fromPlatform().then(
3339
(i) => '${i.version} (${i.buildNumber})',
3440
onError: (Object e) => '? ($e)',
@@ -47,6 +53,7 @@ Future<String> collectDiagnostics(
4753
'Screen: ${media.size.width.round()}×${media.size.height.round()} '
4854
'@${media.devicePixelRatio}, text ×${media.textScaler.scale(10) / 10}',
4955
'Layout: $layout',
56+
'Frames: ${frames ?? 'not enough yet'}',
5057
'Notifications: ready ${notifications.ready}, allowed '
5158
'${notifications.health.allowed}, channels off '
5259
'${notifications.health.blockedChannels}, exact '

‎app/lib/app/theme/app_theme.dart‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ abstract final class AppTheme {
4949
fontFamily: 'Rubik',
5050
textTheme: text,
5151
scaffoldBackgroundColor: scheme.surface,
52-
splashFactory: InkSparkle.splashFactory,
52+
// The default: InkSparkle (a shader) on Android, a plain ripple on
53+
// desktop and iPhone.
5354
appBarTheme: AppBarTheme(
5455
backgroundColor: scheme.surface,
5556
surfaceTintColor: Colors.transparent,

‎app/lib/core/dev/frame_stats.dart‎

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
import 'dart:collection';
2+
import 'dart:math' as math;
3+
import 'dart:ui' show FramePhase, FrameTiming;
4+
5+
import 'package:flutter/scheduler.dart';
6+
7+
/// How smooth the app has been: frame timings since start (the last 600
8+
/// frames), for Settings → Developer → Rendering and diagnostics. Flutter
9+
/// reports them in batches (about once a second in release builds), so
10+
/// watching costs next to nothing.
11+
class FrameStats {
12+
FrameStats._();
13+
14+
static final instance = FrameStats._();
15+
16+
static const _keep = 600;
17+
final _frames = ListQueue<FrameTiming>();
18+
bool _started = false;
19+
20+
void start() {
21+
if (_started) return;
22+
_started = true;
23+
SchedulerBinding.instance.addTimingsCallback(add);
24+
}
25+
26+
/// Records frames (the timings callback; also for tests).
27+
void add(List<FrameTiming> timings) {
28+
_frames.addAll(timings);
29+
while (_frames.length > _keep) {
30+
_frames.removeFirst();
31+
}
32+
}
33+
34+
void reset() => _frames.clear();
35+
36+
/// Null until there are enough frames to say anything.
37+
FrameSummary? summary({required double refreshRate}) {
38+
if (_frames.length < 10) return null;
39+
return FrameSummary.of(_frames.toList(), refreshRate: refreshRate);
40+
}
41+
}
42+
43+
/// Frame timings in numbers.
44+
class FrameSummary {
45+
const FrameSummary({
46+
required this.frames,
47+
required this.refreshRate,
48+
required this.interval,
49+
required this.build,
50+
required this.raster,
51+
required this.overBudget,
52+
});
53+
54+
factory FrameSummary.of(
55+
List<FrameTiming> frames, {
56+
required double refreshRate,
57+
}) {
58+
// Frames come only while something moves: the time between frames of
59+
// one animation shows the real frame rate (idle gaps don't count).
60+
final starts = [
61+
for (final f in frames) f.timestampInMicroseconds(FramePhase.vsyncStart),
62+
];
63+
final gaps = <int>[
64+
for (var i = 1; i < starts.length; i++)
65+
if (starts[i] - starts[i - 1] case final gap
66+
when gap > 0 && gap < 100000)
67+
gap,
68+
];
69+
final budget = refreshRate > 0 ? 1e6 / refreshRate : 1e6 / 60;
70+
final over = frames
71+
.where(
72+
(f) =>
73+
f.buildDuration.inMicroseconds > budget ||
74+
f.rasterDuration.inMicroseconds > budget,
75+
)
76+
.length;
77+
return FrameSummary(
78+
frames: frames.length,
79+
refreshRate: refreshRate,
80+
interval: gaps.isEmpty
81+
? null
82+
: Duration(microseconds: _percentile(gaps, 0.5)),
83+
build: TimingSpread.of([
84+
for (final f in frames) f.buildDuration.inMicroseconds,
85+
]),
86+
raster: TimingSpread.of([
87+
for (final f in frames) f.rasterDuration.inMicroseconds,
88+
]),
89+
overBudget: over / frames.length,
90+
);
91+
}
92+
93+
final int frames;
94+
95+
/// What the display reports (Hz).
96+
final double refreshRate;
97+
98+
/// The usual time between two frames of an animation; null without one.
99+
final Duration? interval;
100+
final TimingSpread build;
101+
final TimingSpread raster;
102+
103+
/// Share of frames whose build or raster took longer than one refresh.
104+
final double overBudget;
105+
106+
/// Frames per second while animating.
107+
double? get fps => interval == null ? null : 1e6 / interval!.inMicroseconds;
108+
109+
@override
110+
String toString() {
111+
final rate = fps;
112+
return [
113+
'${refreshRate.round()} Hz display',
114+
if (rate != null) '${rate.round()} fps while animating',
115+
'build $build',
116+
'raster $raster',
117+
'${(overBudget * 100).toStringAsFixed(1)}% over budget',
118+
'$frames frames',
119+
].join(', ');
120+
}
121+
}
122+
123+
/// p50 / p90 / max of a timing, in ms.
124+
class TimingSpread {
125+
const TimingSpread(this.p50, this.p90, this.max);
126+
127+
factory TimingSpread.of(List<int> micros) => TimingSpread(
128+
_percentile(micros, 0.5),
129+
_percentile(micros, 0.9),
130+
micros.reduce(math.max),
131+
);
132+
133+
final int p50;
134+
final int p90;
135+
final int max;
136+
137+
static String _ms(int micros) => (micros / 1000).toStringAsFixed(1);
138+
139+
@override
140+
String toString() => 'p50 ${_ms(p50)} / p90 ${_ms(p90)} / max ${_ms(max)} ms';
141+
}
142+
143+
int _percentile(List<int> values, double p) {
144+
final sorted = [...values]..sort();
145+
return sorted[((sorted.length - 1) * p).round()];
146+
}

‎app/lib/features/developer/developer_page.dart‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import '../../app/sync_providers.dart';
1717
import '../../app/widget_controller.dart';
1818
import '../../app/widgets/common.dart';
1919
import '../../core/dev/dev_log.dart';
20+
import '../../core/dev/frame_stats.dart';
2021
import '../../core/home_widget/today_widget.dart';
2122
import '../../core/icons/lec_icons.dart';
2223
import '../../core/notifications/android_device.dart';
@@ -392,6 +393,47 @@ class _DeveloperPageState extends ConsumerState<DeveloperPage> {
392393

393394
// ------------------------------------------------------------- device --
394395

396+
/// How smooth the app is here: the display's rate, and the frames since
397+
/// start (or since Reset). Scroll or swipe the Week view, then refresh.
398+
Widget _renderingTools() {
399+
final view = View.of(context);
400+
final rate = view.display.refreshRate;
401+
final summary = FrameStats.instance.summary(refreshRate: rate);
402+
final fps = summary?.fps;
403+
return Column(
404+
crossAxisAlignment: CrossAxisAlignment.stretch,
405+
children: [
406+
_info(
407+
'Display',
408+
'${rate.round()} Hz, ${view.devicePixelRatio}× pixels',
409+
),
410+
_info(
411+
'While animating',
412+
fps == null
413+
? 'Nothing measured yet: swipe the Week view, then refresh'
414+
: '${fps.round()} fps (a frame every '
415+
'${(summary!.interval!.inMicroseconds / 1000).toStringAsFixed(1)} ms)',
416+
// Flutter's Linux engine draws at 60 fps whatever the display.
417+
warn: fps != null && fps < rate * 0.9,
418+
),
419+
if (summary != null) ...[
420+
_info('Build', '${summary.build}'),
421+
_info('Raster', '${summary.raster}'),
422+
_info(
423+
'Over budget',
424+
'${(summary.overBudget * 100).toStringAsFixed(1)}% of '
425+
'${summary.frames} frames took longer than one refresh',
426+
warn: summary.overBudget > 0.05,
427+
),
428+
],
429+
_action(LecIcons.refresh, 'Reset the frame counts', () {
430+
FrameStats.instance.reset();
431+
_refresh();
432+
}),
433+
],
434+
);
435+
}
436+
395437
Widget _deviceTools() {
396438
final media = MediaQuery.of(context);
397439
final now = DateTime.now();
@@ -582,6 +624,8 @@ class _DeveloperPageState extends ConsumerState<DeveloperPage> {
582624
}),
583625
),
584626
],
627+
const SectionHeader(title: 'Rendering'),
628+
_renderingTools(),
585629
const SectionHeader(title: 'This device'),
586630
_deviceTools(),
587631
const SectionHeader(title: 'Log (newest first)'),

0 commit comments

Comments
 (0)