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

performance.bench.ts

77 lines2.7 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 { describe, test } 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 test("sort 1000 threads by recent activity", async ({ bench }) => {
45 await bench("sort", () => {
46 sortThreads(threads, "updated_at");
47 }).run();
48 });
49 test("sort 1000 active threads", async ({ bench }) => {
50 await bench("sort", () => {
51 sortActiveThreadsByOrderKey(threads);
52 }).run();
53 });
54 test("sort 1000 keyless pinned threads", async ({ bench }) => {
55 await bench("sort", () => {
56 sortPinnedThreadsByOrderKey(threads);
57 }).run();
58 });
59 test("select latest project thread from 1000 threads", async ({ bench }) => {
60 await bench("select", () => {
61 getLatestThreadForProject(threads, projectId, "updated_at");
62 }).run();
63 });
64 test("derive plan from 500 activities with 5 plan updates", async ({ bench }) => {
65 await bench("derive", () => {
66 deriveActivePlanState(activities, turnId);
67 }).run();
68 });
69 test("format 24 hourly usage labels and tooltips", async ({ bench }) => {
70 await bench("format", () => {
71 hours.map((hour) => [
72 formatHourShort(hour, "America/New_York"),
73 formatRelativeHourShort(hour, referenceTime, "America/New_York"),
74 ]);
75 }).run();
76 });
77});