Rebuild only changed list rows and lay out big artifact sections lazily
Runs and chat session rows are memoized on their own data (MemoSubtree), so a run event or a chat's running change rebuilds one row instead of every built row. The artifact gallery's open sections are lazy slivers revealed by a sliver open/close animation, and thumbnails decode at display size. Benches in test/perf measure both.
This commit is contained in:
@@ -175,6 +175,13 @@ class _ChatSessionsScreenState extends State<ChatSessionsScreen> {
|
||||
widget.onOpen(session);
|
||||
}
|
||||
|
||||
// Methods rather than closures, so the list's memoized rows see the same
|
||||
// callbacks from one build to the next.
|
||||
void _reopen(JsonMap session) => _controller.reopen(_sessionId(session));
|
||||
|
||||
void _star(JsonMap session) =>
|
||||
_controller.star(_sessionId(session), session['starred'] != true);
|
||||
|
||||
Future<void> _hide(JsonMap session) async {
|
||||
await _controller.hide(_sessionId(session));
|
||||
_undoTimer?.cancel();
|
||||
@@ -226,12 +233,8 @@ class _ChatSessionsScreenState extends State<ChatSessionsScreen> {
|
||||
onOpen: _open,
|
||||
onRename: _rename,
|
||||
onClose: _close,
|
||||
onReopen: (session) =>
|
||||
_controller.reopen(_sessionId(session)),
|
||||
onStar: (session) => _controller.star(
|
||||
_sessionId(session),
|
||||
session['starred'] != true,
|
||||
),
|
||||
onReopen: _reopen,
|
||||
onStar: _star,
|
||||
onHide: _hide,
|
||||
onClearSearch: () {
|
||||
_search.clear();
|
||||
|
||||
@@ -5,8 +5,7 @@ import '../../../../core/api_gateway.dart';
|
||||
import '../../domain/chat_sessions.dart';
|
||||
import 'chat_adaptive.dart';
|
||||
import 'chat_sessions_body.dart';
|
||||
import 'session_actions.dart';
|
||||
import 'session_row_content.dart';
|
||||
import 'session_row_memo.dart';
|
||||
import '../../../../ui/adaptive/floating_bar_layout.dart';
|
||||
|
||||
class CupertinoSessionList extends StatelessWidget {
|
||||
@@ -96,7 +95,7 @@ class CupertinoSessionList extends StatelessWidget {
|
||||
final id = '${session['id'] ?? ''}';
|
||||
final error = errorFor(id);
|
||||
return [
|
||||
ChatSessionRow(
|
||||
memoChatSessionRow(
|
||||
session: session,
|
||||
selected: id == activeSessionId,
|
||||
duplicateTitles: duplicateTitles,
|
||||
@@ -104,15 +103,11 @@ class CupertinoSessionList extends StatelessWidget {
|
||||
// A refusal below the row separates it instead.
|
||||
divider: divider && error == null,
|
||||
onOpen: onOpen,
|
||||
onAction: (action) => _dispatch(
|
||||
action,
|
||||
session,
|
||||
onStar: onStar,
|
||||
onRename: onRename,
|
||||
onClose: onClose,
|
||||
onReopen: onReopen,
|
||||
onHide: onHide,
|
||||
),
|
||||
onStar: onStar,
|
||||
onRename: onRename,
|
||||
onClose: onClose,
|
||||
onReopen: onReopen,
|
||||
onHide: onHide,
|
||||
),
|
||||
if (error != null)
|
||||
ChatRowError(
|
||||
@@ -124,30 +119,6 @@ class CupertinoSessionList extends StatelessWidget {
|
||||
}
|
||||
}
|
||||
|
||||
/// Routes a row's menu choice to the list's callbacks.
|
||||
void _dispatch(
|
||||
SessionAction action,
|
||||
JsonMap session, {
|
||||
required ValueChanged<JsonMap> onStar,
|
||||
required ValueChanged<JsonMap> onRename,
|
||||
required ValueChanged<JsonMap> onClose,
|
||||
required ValueChanged<JsonMap> onReopen,
|
||||
required ValueChanged<JsonMap> onHide,
|
||||
}) {
|
||||
switch (action) {
|
||||
case SessionAction.star:
|
||||
onStar(session);
|
||||
case SessionAction.rename:
|
||||
onRename(session);
|
||||
case SessionAction.close:
|
||||
onClose(session);
|
||||
case SessionAction.reopen:
|
||||
onReopen(session);
|
||||
case SessionAction.hide:
|
||||
onHide(session);
|
||||
}
|
||||
}
|
||||
|
||||
/// A directory's name above its chats, like a grouped table's header.
|
||||
class _DirectoryHeader extends StatelessWidget {
|
||||
const _DirectoryHeader(this.directory);
|
||||
|
||||
@@ -6,8 +6,7 @@ import '../../../../core/api_gateway.dart';
|
||||
import '../../domain/chat_sessions.dart';
|
||||
import 'chat_adaptive.dart';
|
||||
import 'chat_sessions_body.dart';
|
||||
import 'session_actions.dart';
|
||||
import 'session_row_content.dart';
|
||||
import 'session_row_memo.dart';
|
||||
|
||||
class MaterialSessionList extends StatelessWidget {
|
||||
const MaterialSessionList({
|
||||
@@ -97,7 +96,7 @@ class MaterialSessionList extends StatelessWidget {
|
||||
final id = '${session['id'] ?? ''}';
|
||||
final error = errorFor(id);
|
||||
return [
|
||||
ChatSessionRow(
|
||||
memoChatSessionRow(
|
||||
session: session,
|
||||
selected: id == activeSessionId,
|
||||
duplicateTitles: duplicateTitles,
|
||||
@@ -105,15 +104,11 @@ class MaterialSessionList extends StatelessWidget {
|
||||
// A refusal below the row separates it instead.
|
||||
divider: divider && error == null,
|
||||
onOpen: onOpen,
|
||||
onAction: (action) => _dispatch(
|
||||
action,
|
||||
session,
|
||||
onStar: onStar,
|
||||
onRename: onRename,
|
||||
onClose: onClose,
|
||||
onReopen: onReopen,
|
||||
onHide: onHide,
|
||||
),
|
||||
onStar: onStar,
|
||||
onRename: onRename,
|
||||
onClose: onClose,
|
||||
onReopen: onReopen,
|
||||
onHide: onHide,
|
||||
),
|
||||
if (error != null)
|
||||
ChatRowError(
|
||||
@@ -124,27 +119,3 @@ class MaterialSessionList extends StatelessWidget {
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
/// Routes a row's menu choice to the list's callbacks.
|
||||
void _dispatch(
|
||||
SessionAction action,
|
||||
JsonMap session, {
|
||||
required ValueChanged<JsonMap> onStar,
|
||||
required ValueChanged<JsonMap> onRename,
|
||||
required ValueChanged<JsonMap> onClose,
|
||||
required ValueChanged<JsonMap> onReopen,
|
||||
required ValueChanged<JsonMap> onHide,
|
||||
}) {
|
||||
switch (action) {
|
||||
case SessionAction.star:
|
||||
onStar(session);
|
||||
case SessionAction.rename:
|
||||
onRename(session);
|
||||
case SessionAction.close:
|
||||
onClose(session);
|
||||
case SessionAction.reopen:
|
||||
onReopen(session);
|
||||
case SessionAction.hide:
|
||||
onHide(session);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
import '../../../../core/api_gateway.dart';
|
||||
import '../../../../ui/layout/memo_subtree.dart';
|
||||
import '../../domain/chat_sessions.dart';
|
||||
import 'session_actions.dart';
|
||||
import 'session_row_content.dart';
|
||||
|
||||
/// A chat row that rebuilds only when its own session or state changes, so a
|
||||
/// running-state change in one chat does not rebuild every row of the list.
|
||||
///
|
||||
/// The list's callbacks are part of the memo: the screen passes its own
|
||||
/// methods, so they compare equal from one build to the next.
|
||||
Widget memoChatSessionRow({
|
||||
required JsonMap session,
|
||||
required bool selected,
|
||||
required Set<String> duplicateTitles,
|
||||
required bool unseen,
|
||||
required bool divider,
|
||||
required ValueChanged<JsonMap> onOpen,
|
||||
required ValueChanged<JsonMap> onStar,
|
||||
required ValueChanged<JsonMap> onRename,
|
||||
required ValueChanged<JsonMap> onClose,
|
||||
required ValueChanged<JsonMap> onReopen,
|
||||
required ValueChanged<JsonMap> onHide,
|
||||
}) => MemoSubtree(
|
||||
key: ValueKey('chat-row-memo-${session['id'] ?? ''}'),
|
||||
memo: (
|
||||
MemoMap(session),
|
||||
selected,
|
||||
// The row reads the set only for its own title.
|
||||
duplicateTitles.contains(chatSessionTitle(session)),
|
||||
unseen,
|
||||
divider,
|
||||
onOpen,
|
||||
onStar,
|
||||
onRename,
|
||||
onClose,
|
||||
onReopen,
|
||||
onHide,
|
||||
),
|
||||
builder: (_) => ChatSessionRow(
|
||||
session: session,
|
||||
selected: selected,
|
||||
duplicateTitles: duplicateTitles,
|
||||
unseen: unseen,
|
||||
divider: divider,
|
||||
onOpen: onOpen,
|
||||
onAction: (action) => switch (action) {
|
||||
SessionAction.star => onStar(session),
|
||||
SessionAction.rename => onRename(session),
|
||||
SessionAction.close => onClose(session),
|
||||
SessionAction.reopen => onReopen(session),
|
||||
SessionAction.hide => onHide(session),
|
||||
},
|
||||
),
|
||||
);
|
||||
Reference in New Issue
Block a user