mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-11-16 13:00:55 +00:00
* 🧵 feat(client): Flat Message Thread Renderer Behind a Flag Adds a keyed thread index and an O(depth) visible-path resolver so the message list can render as a flat, memoized list instead of one React level per message. The recursive MultiMessage path stays the default; the flat path is enabled per page with the LC_FLAT_THREAD localStorage key or VITE_FLAT_THREAD at build time. Also adds a react-scan/CDP benchmark lane (e2e/benchmarks-tree) that A/Bs both render paths on a seeded 240-row thread, plus a parity config that runs the branch-sensitive mock specs with the flat path on. * 🙈 chore: Ignore the Tree Benchmark Output Directory * 🪢 refactor(client): Move Sibling Selection to Feature-Owned Jotai State Codex round 1 on #15633. The message thread's sibling selection moves out of the Recoil store into a Jotai atom family owned by the thread feature, shared by the recursive and flat renderers, the share view, and the focus, resume and clear writers. Consumers that watch several branch points read them through one derived atom via useSyncExternalStore, so a token-only cache write costs no render. Also keeps the raw cache object as a thread row's reuse identity (file hydration now happens on the row, keyed on the file map), sets the flat flag before the parity config snapshots the server env, and gives the seeded alternate branch consistent turn numbers. * 🧹 style: Sort Imports in the Thread Renderer Files * 📏 chore(e2e): Sample Renderer CPU and Post-GC Heap in the Tree Benchmark Adds a CDP resource probe to each phase: renderer-process CPU time (all threads), JS heap after a forced GC (retained memory rather than allocation churn), DOM node and listener counts. Also lets TREE_PARITY_MATCH pick which mock specs the parity config runs, and derives the deep-switch phase label from the seeded thread size.
99 lines
3.7 KiB
TypeScript
99 lines
3.7 KiB
TypeScript
import type { SeedMessage } from '../specs/mock/db';
|
|
|
|
/**
|
|
* Deterministic transcript for the message-tree render benchmark: a long
|
|
* linear spine with two regenerate branches, one shallow (short alternate
|
|
* continuation) and one at the leaf, so both a deep path swap and a
|
|
* leaf-only sibling switch can be measured against the same thread.
|
|
*/
|
|
/** Turns per seeded thread; `TREE_PERF_TURNS` overrides it for scaling runs. */
|
|
export const TURNS = Number(process.env.TREE_PERF_TURNS) || 120;
|
|
export const ROWS = TURNS * 2;
|
|
export const SHALLOW_BRANCH_TURN = 3;
|
|
export const SHALLOW_BRANCH_CONTINUATION_TURNS = 2;
|
|
export const ROOT_PARENT = '00000000-0000-0000-0000-000000000000';
|
|
|
|
const SENTENCE =
|
|
'The rollout plan sequences every dependent service behind a single feature flag so rollbacks stay one toggle away. ';
|
|
|
|
export function marker(label: string): string {
|
|
return `TREEBENCH-${label}`;
|
|
}
|
|
|
|
export function turnHeading(label: string, turn: number): string {
|
|
return `${marker(label)} section ${turn}`;
|
|
}
|
|
|
|
export function altHeading(label: string, turn: number): string {
|
|
return `${marker(label)} alternate ${turn}`;
|
|
}
|
|
|
|
function assistantBody(heading: string, turn: number): string {
|
|
let body = `## ${heading}\n\n${SENTENCE}${SENTENCE}\n\n`;
|
|
body += `- ${marker('point')} one for turn ${turn}\n`;
|
|
body += `- ${marker('point')} two for turn ${turn}\n\n`;
|
|
if (turn % 3 === 0) {
|
|
body +=
|
|
'```ts\nexport function rollout(stage: number): boolean {\n return stage > 0;\n}\n```\n\n';
|
|
}
|
|
if (turn % 4 === 0) {
|
|
body += '| Service | Requests |\n| --- | --- |\n| gateway | 120000 |\n| worker | 135500 |\n\n';
|
|
}
|
|
return body;
|
|
}
|
|
|
|
function userRow(label: string, id: string, parentMessageId: string, turn: number): SeedMessage {
|
|
return {
|
|
messageId: id,
|
|
parentMessageId,
|
|
text: `${marker(label)} prompt ${turn}: walk me through the rollout for stage ${turn}.`,
|
|
isCreatedByUser: true,
|
|
sender: 'User',
|
|
};
|
|
}
|
|
|
|
function assistantRow(id: string, parentMessageId: string, heading: string, turn: number) {
|
|
return {
|
|
messageId: id,
|
|
parentMessageId,
|
|
text: assistantBody(heading, turn),
|
|
isCreatedByUser: false,
|
|
sender: 'Assistant',
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Seed order doubles as creation order, so an alternate sibling is emitted
|
|
* BEFORE the spine row it competes with: the newest sibling is the default
|
|
* selection, and the spine must stay the default visible path.
|
|
*/
|
|
export function buildTreeMessages(label: string): SeedMessage[] {
|
|
const messages: SeedMessage[] = [];
|
|
let parentMessageId = ROOT_PARENT;
|
|
for (let turn = 1; turn <= TURNS; turn += 1) {
|
|
const userId = `${label}-user-${turn}`;
|
|
messages.push(userRow(label, userId, parentMessageId, turn));
|
|
const assistantId = `${label}-assistant-${turn}`;
|
|
if (turn === SHALLOW_BRANCH_TURN) {
|
|
const altId = `${label}-assistant-${turn}-alt`;
|
|
messages.push(assistantRow(altId, userId, altHeading(label, turn), turn));
|
|
let altParent = altId;
|
|
for (let extra = 1; extra <= SHALLOW_BRANCH_CONTINUATION_TURNS; extra += 1) {
|
|
const altTurn = 1000 + extra;
|
|
const altUser = `${label}-alt-user-${extra}`;
|
|
messages.push(userRow(label, altUser, altParent, altTurn));
|
|
const altAssistant = `${label}-alt-assistant-${extra}`;
|
|
messages.push(assistantRow(altAssistant, altUser, altHeading(label, altTurn), altTurn));
|
|
altParent = altAssistant;
|
|
}
|
|
}
|
|
if (turn === TURNS) {
|
|
messages.push(
|
|
assistantRow(`${label}-assistant-${turn}-alt`, userId, altHeading(label, turn), turn),
|
|
);
|
|
}
|
|
messages.push(assistantRow(assistantId, userId, turnHeading(label, turn), turn));
|
|
parentMessageId = assistantId;
|
|
}
|
|
return messages;
|
|
}
|