Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

performance.bench.ts

65 lines2.3 KB

1import { EventId, ProjectId, TurnId, type OrchestrationThreadActivity } from "@t3tools/contracts";
2import {
3 getLatestThreadForProject,
4 sortActiveThreadsByOrderKey,
5 sortPinnedThreadsByOrderKey,
6 sortThreads,
7} from "@t3tools/client-runtime/state/thread-sort";
8import { formatHourShort, formatRelativeHourShort } from "@t3tools/shared/usageFormat";
9import { bench, describe } from "vite-plus/test";
10​
11import { deriveActivePlanState } from "./session-logic";
12​
13const projectId = ProjectId.make("benchmark-project");
14const turnId = TurnId.make("benchmark-turn");
15const start = Date.parse("2026-08-11T00:00:00.000Z");
16const threads = Array.from({ length: 1_000 }, (_, index) => {
17 const timestamp = new Date(start + ((index * 997) % 1_000) * 60_000).toISOString();
18 return {
19 id: `thread-${index}`,
20 projectId,
21 archivedAt: null,
22 createdAt: timestamp,
23 updatedAt: timestamp,
24 latestUserMessageAt: timestamp,
25 unsettledAt: null,
26 };
27});
28const activities: OrchestrationThreadActivity[] = Array.from({ length: 500 }, (_, index) => ({
29 id: EventId.make(`activity-${index}`),
30 turnId,
31 sequence: index,
32 createdAt: new Date(start + index * 1_000).toISOString(),
33 kind: index % 100 === 0 ? "turn.plan.updated" : "tool.completed",
34 summary: "Benchmark activity",
35 tone: "info",
36 payload: index % 100 === 0 ? { plan: [{ step: "Run checks", status: "inProgress" }] } : {},
37}));
38const hours = Array.from({ length: 24 }, (_, index) =>
39 new Date(start + index * 3_600_000).toISOString(),
40);
41const referenceTime = "2026-08-12T00:00:00.000Z";
42​
43describe("client performance", () => {
44 bench("sort 1000 threads by recent activity", () => {
45 sortThreads(threads, "updated_at");
46 });
47 bench("sort 1000 active threads", () => {
48 sortActiveThreadsByOrderKey(threads);
49 });
50 bench("sort 1000 keyless pinned threads", () => {
51 sortPinnedThreadsByOrderKey(threads);
52 });
53 bench("select latest project thread from 1000 threads", () => {
54 getLatestThreadForProject(threads, projectId, "updated_at");
55 });
56 bench("derive plan from 500 activities with 5 plan updates", () => {
57 deriveActivePlanState(activities, turnId);
58 });
59 bench("format 24 hourly usage labels and tooltips", () => {
60 hours.map((hour) => [
61 formatHourShort(hour, "America/New_York"),
62 formatRelativeHourShort(hour, referenceTime, "America/New_York"),
63 ]);
64 });
65});