App: replace a silent socket instead of hanging; blink the terminal cursor on a timer; keep one markdown cache entry per streamed reply
A socket that outlived a sleep or network change looked open, so every queued request waited its own 30 s timeout behind the last until the page was reopened. The client now replaces a socket whose request times out unheard (or after two timeouts in a row), and probes it with a ping after a quiet spell or on returning to the foreground. The terminal's blinking cursor ran a Ticker (a frame every vsync); a 530 ms timer now flips it. Streamed deltas no longer flood the markdown cache and evict finished answers. Adds tool/perf/idle_session_bench.mjs (idle frames, long-session heap, snapshot census) and notes/perf-hangs-idle.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -7,8 +7,13 @@ import 'chat_markdown.dart';
|
||||
/// A lazily built transcript disposes rows scrolled out of view, so scrolling
|
||||
/// back would parse the same answer again. Blocks are immutable and depend on
|
||||
/// the text alone, so one parse serves every later view of that text. Bounded
|
||||
/// by entries and by held characters, evicting the least recently used first,
|
||||
/// so a long streamed reply's intermediate texts cannot grow it without limit.
|
||||
/// by entries and by held characters, evicting the least recently used first.
|
||||
///
|
||||
/// A streamed reply asks for a longer text on every delta. Each new text
|
||||
/// replaces the newest entry when that entry is its prefix, so a reply holds
|
||||
/// one entry while it streams instead of one per delta: its intermediate
|
||||
/// texts would otherwise fill the character budget and evict every finished
|
||||
/// answer, which then parse again when scrolled back into view.
|
||||
class ChatMarkdownCache {
|
||||
ChatMarkdownCache({this.maxEntries = 400, this.maxChars = 1000000});
|
||||
|
||||
@@ -28,6 +33,13 @@ class ChatMarkdownCache {
|
||||
final blocks = List<MarkdownBlock>.unmodifiable(parseMarkdown(text));
|
||||
parses++;
|
||||
if (text.length > maxChars) return blocks;
|
||||
if (_blocks.isNotEmpty) {
|
||||
final newest = _blocks.keys.last;
|
||||
if (newest.length < text.length && text.startsWith(newest)) {
|
||||
_blocks.remove(newest);
|
||||
_chars -= newest.length;
|
||||
}
|
||||
}
|
||||
_blocks[text] = blocks;
|
||||
_chars += text.length;
|
||||
while (_blocks.length > maxEntries || _chars > maxChars) {
|
||||
|
||||
Reference in New Issue
Block a user