perf(chat): isolate usage updates from transcript rendering
This commit is contained in:
@@ -35,6 +35,7 @@ class ChatThreadController extends ChangeNotifier {
|
||||
isAlive: () => !_disposed,
|
||||
);
|
||||
StreamSubscription<JsonMap>? _subscription;
|
||||
final _transcriptChanges = ChangeNotifier();
|
||||
|
||||
List<JsonMap> _messages = const [];
|
||||
bool _running = false;
|
||||
@@ -55,6 +56,9 @@ class ChatThreadController extends ChangeNotifier {
|
||||
bool _resyncAgain = false;
|
||||
|
||||
List<JsonMap> get messages => _messages;
|
||||
|
||||
/// Usage-only snapshots refresh Info, not the expensive transcript tree.
|
||||
Listenable get transcriptChanges => _transcriptChanges;
|
||||
bool get running => _running;
|
||||
String? get liveAssistantMessageId => _liveAssistantMessageId;
|
||||
bool get loaded => _loaded;
|
||||
@@ -239,7 +243,7 @@ class ChatThreadController extends ChangeNotifier {
|
||||
final usage = chatUsageSnapshot(body['usage']);
|
||||
if (usage == null || !_reportedUsage(usage)) return;
|
||||
_usage = usage;
|
||||
_notify();
|
||||
_notify(transcript: false);
|
||||
return;
|
||||
}
|
||||
if (body['kind'] == 'form') {
|
||||
@@ -334,13 +338,16 @@ class ChatThreadController extends ChangeNotifier {
|
||||
_notify();
|
||||
}
|
||||
|
||||
void _notify() {
|
||||
if (!_disposed) notifyListeners();
|
||||
void _notify({bool transcript = true}) {
|
||||
if (_disposed) return;
|
||||
notifyListeners();
|
||||
if (transcript && !_disposed) _transcriptChanges.notifyListeners();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_disposed = true;
|
||||
_transcriptChanges.dispose();
|
||||
_generation++;
|
||||
unawaited(_subscription?.cancel());
|
||||
super.dispose();
|
||||
|
||||
@@ -575,7 +575,7 @@ class _ChatThreadViewState extends State<ChatThreadView> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => AnimatedBuilder(
|
||||
animation: _controller,
|
||||
animation: _controller.transcriptChanges,
|
||||
builder: (context, _) {
|
||||
final cupertino =
|
||||
chatControlsStyleOf(context) == ChatControlsStyle.cupertino;
|
||||
|
||||
Reference in New Issue
Block a user