Terminal feed: on the web, show streaming output at most every 32 ms
In the browser a frame rasterises on the thread that parses output, so a stream drawn at 60 frames a second spends half its time drawing. With deferShows (the web default) output written less than a gap after the last show is shown when the gap has passed; output after a quiet spell (an echo) still shows at once. Natively frames rasterise on their own thread and written output keeps showing at once. The stream bench measures the stream without its final 600 ms wait for frame timings. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -55,8 +55,8 @@ void main() {
|
||||
},
|
||||
);
|
||||
|
||||
test('the view is shown once what waits is written, and while a burst '
|
||||
'is behind at most every show gap', () async {
|
||||
test('output after a quiet spell is shown at once; streaming output at '
|
||||
'most every show gap', () async {
|
||||
var shown = 0;
|
||||
final writes = <String>[];
|
||||
final feed = ChatShellTerminalFeed(
|
||||
@@ -64,10 +64,11 @@ void main() {
|
||||
show: () => shown++,
|
||||
budget: Duration.zero,
|
||||
slice: 10,
|
||||
showGap: const Duration(hours: 1),
|
||||
showGap: const Duration(milliseconds: 300),
|
||||
deferShows: true,
|
||||
);
|
||||
feed.add('abc', 3);
|
||||
// Written whole at once: shown at once.
|
||||
// The first output, written whole at once: shown at once.
|
||||
expect(writes, ['abc']);
|
||||
expect(shown, 1);
|
||||
feed.add('x' * 35, 38);
|
||||
@@ -78,18 +79,50 @@ void main() {
|
||||
expect(shown, 1);
|
||||
await turn();
|
||||
await turn();
|
||||
// Caught up: the final state is shown.
|
||||
// Caught up within the gap: shown when the gap has passed.
|
||||
expect(writes.skip(1).join(), 'x' * 35);
|
||||
expect(feed.idle, isTrue);
|
||||
expect(shown, 1);
|
||||
await Future<void>.delayed(const Duration(milliseconds: 400));
|
||||
expect(shown, 2);
|
||||
// After a quiet spell: at once again.
|
||||
await Future<void>.delayed(const Duration(milliseconds: 400));
|
||||
feed.add('q', 39);
|
||||
expect(shown, 3);
|
||||
// An action waiting behind output sees it shown first.
|
||||
feed.add('y' * 25, 63);
|
||||
feed.add('y' * 25, 64);
|
||||
var shownForAction = -1;
|
||||
feed.then(() => shownForAction = shown);
|
||||
for (var i = 0; i < 5; i++) {
|
||||
await turn();
|
||||
}
|
||||
expect(shownForAction, 3);
|
||||
expect(shownForAction, 4);
|
||||
expect(shown, 4);
|
||||
feed.dispose();
|
||||
});
|
||||
|
||||
test('without deferred shows (natively) written output is shown at once; '
|
||||
'only a burst still behind waits for the gap', () async {
|
||||
var shown = 0;
|
||||
final feed = ChatShellTerminalFeed(
|
||||
(_, _) {},
|
||||
show: () => shown++,
|
||||
budget: Duration.zero,
|
||||
slice: 10,
|
||||
showGap: const Duration(hours: 1),
|
||||
deferShows: false,
|
||||
);
|
||||
feed.add('abc', 3);
|
||||
feed.add('def', 6);
|
||||
expect(shown, 2);
|
||||
feed.add('x' * 35, 41);
|
||||
await turn();
|
||||
await turn();
|
||||
expect(shown, 2);
|
||||
for (var i = 0; i < 3; i++) {
|
||||
await turn();
|
||||
}
|
||||
expect(feed.idle, isTrue);
|
||||
expect(shown, 3);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user