Created
October 12, 2026 11:03
-
-
Save realhasanshoaib/3b3d80b40d7f7b58c899011f0507e240 to your computer and use it in GitHub Desktop.
T3 Code performance audit: synthetic fixtures, no user data. Run discovery-bench.mjs from apps/server/.audit with repository dependencies; error-lookup-bench.py uses Python SQLite.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import fs from 'node:fs'; | |
| import assert from 'node:assert/strict'; | |
| import * as Effect from 'effect/Effect'; | |
| import * as Layer from 'effect/Layer'; | |
| import * as DateTime from 'effect/DateTime'; | |
| import * as SqlClient from 'effect/sql/SqlClient'; | |
| import * as Statement from 'effect/sql/Statement'; | |
| import * as ProjectionStore from '../src/orchestration-v2/ProjectionStore.ts'; | |
| import * as SqlitePersistence from '../src/persistence/Sqlite.ts'; | |
| import { EventId, ProjectId, ProviderInstanceId, ThreadId } from '@t3tools/contracts'; | |
| const now = DateTime.makeUnsafe('2026-10-12T12:00:00Z'); | |
| const instanceId = ProviderInstanceId.make('codex'); | |
| const layer = ProjectionStore.layer.pipe(Layer.provideMerge(SqlitePersistence.layerMemory)); | |
| const result = await Effect.runPromise(Effect.gen(function* () { | |
| const store = yield* ProjectionStore.ProjectionStoreV2; | |
| const sql = yield* SqlClient.SqlClient; | |
| for (let i = 0; i < 500; i++) { | |
| const id = ThreadId.make('thread-' + i); | |
| yield* store.apply({id: EventId.make('event-' + i), type: 'thread.created', threadId: id, occurredAt: now, payload: { | |
| id, projectId: ProjectId.make('project'), createdBy: 'user', creationSource: 'web', title: 'Thread ' + i, | |
| providerInstanceId: instanceId, modelSelection: {instanceId, model: 'test'}, runtimeMode: 'full-access', | |
| interactionMode: 'default', branch: 'feature-' + i, worktreePath: null, activeProviderThreadId: null, | |
| lineage: {parentThreadId: null, relationshipToParent: null, rootThreadId: id}, forkedFrom: null, | |
| createdAt: now, updatedAt: now, archivedAt: null, settledOverride: null, settledAt: null, | |
| lastVisitedAt: null, deletedAt: null, | |
| }}); | |
| } | |
| yield* sql` | |
| WITH RECURSIVE items(ordinal) AS (SELECT 1 UNION ALL SELECT ordinal+1 FROM items WHERE ordinal<50000) | |
| INSERT INTO orchestration_v2_projection_turn_items | |
| (turn_item_id,thread_id,run_id,node_id,ordinal,type,status,updated_at,payload_json) | |
| SELECT 'item-' || ordinal, 'thread-' || (ordinal % 500), NULL,NULL,ordinal, | |
| 'command_execution','completed','2026-10-12',json_object('output', hex(zeroblob(256))) FROM items | |
| `; | |
| const run = Effect.fn(function* (read) { | |
| const timings=[]; | |
| let snapshot; | |
| for (let i=0;i<9;i++) { | |
| const start=performance.now(); | |
| snapshot=yield* read; | |
| timings.push(performance.now()-start); | |
| } | |
| const statements=[]; | |
| const record=statement=>Effect.sync(()=>{statements.push(statement.compile()[0]); return statement;}); | |
| yield* read.pipe(Effect.provideService(Statement.CurrentTransformer,record)); | |
| const selectQueries=statements.filter(query=>query.trim().startsWith('SELECT')); | |
| return {median_ms:timings.toSorted((a,b)=>a-b)[4], minimum_ms:Math.min(...timings), thread_count:snapshot.threads.length, | |
| history_queries:selectQueries.filter(q=>/projection_(runs|turn_items|messages|provider_threads)/.test(q)).length, | |
| select_queries:selectQueries.length}; | |
| }); | |
| const shell = yield* store.getShellSnapshot({unsettledOnly:true}); | |
| const discovery = yield* store.getPullRequestDiscoverySnapshot({unsettledOnly:true}); | |
| const fields=['id','projectId','branch','worktreePath','archivedAt','settledOverride','settledAt','branchPullRequest','linkedPullRequest','pullRequests']; | |
| const metadata = threads => threads.map(thread => Object.fromEntries(fields.map(key=>[key,thread[key]]))); | |
| assert.deepEqual(metadata(discovery.threads),metadata(shell.threads)); | |
| return {threads:500, completed_items:50000, metadata_matches:true, before:yield* run(store.getShellSnapshot({unsettledOnly:true})), | |
| after:yield* run(store.getPullRequestDiscoverySnapshot({unsettledOnly:true}))}; | |
| }).pipe(Effect.provide(layer))); | |
| fs.writeFileSync(new URL('./discovery-bench.json',import.meta.url),JSON.stringify(result,null,2)); | |
| console.log(JSON.stringify(result,null,2)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import json | |
| import sqlite3 | |
| import statistics | |
| import time | |
| from pathlib import Path | |
| c = sqlite3.connect(':memory:') | |
| c.executescript(''' | |
| CREATE TABLE orchestration_v2_projection_turn_items ( | |
| turn_item_id TEXT PRIMARY KEY, thread_id TEXT, run_id TEXT, node_id TEXT, | |
| ordinal INTEGER, type TEXT, status TEXT, updated_at TEXT, payload_json TEXT); | |
| CREATE INDEX orchestration_v2_projection_turn_items_thread_run_idx | |
| ON orchestration_v2_projection_turn_items(thread_id,run_id); | |
| ''') | |
| c.executemany('INSERT INTO orchestration_v2_projection_turn_items VALUES (?,?,?,?,?,?,?,?,?)', | |
| [('item-'+str(i),'thread','run','root',i,'command_execution','completed','2026-10-01',json.dumps({'output':'x'*512})) for i in range(50000)]) | |
| c.executemany('INSERT INTO orchestration_v2_projection_turn_items VALUES (?,?,?,?,?,?,?,?,?)',[ | |
| ('root-error','thread','run','root',50001,'error','failed','2026-10-02',json.dumps({'failure':{'class':'usage_limit'}})), | |
| ('child-error','thread','run','child',50002,'error','failed','2026-10-03',json.dumps({'failure':{'class':'provider'}}))]) | |
| q = '''SELECT item.payload_json FROM orchestration_v2_projection_turn_items item | |
| INDEXED BY orchestration_v2_projection_turn_items_thread_run_idx | |
| WHERE item.thread_id=? AND item.run_id=? AND item.type='error' | |
| AND item.status='failed' AND item.node_id IS ? | |
| ORDER BY item.updated_at DESC,item.ordinal DESC,item.turn_item_id DESC LIMIT 1''' | |
| args=('thread','run','root') | |
| def measure(query): | |
| times=[] | |
| for _ in range(9): | |
| s=time.perf_counter() | |
| result=c.execute(query,args).fetchone() | |
| times.append((time.perf_counter()-s)*1000) | |
| assert json.loads(result[0])['failure']['class']=='usage_limit' | |
| steps=0 | |
| def count(): | |
| nonlocal steps | |
| steps+=100 | |
| return 0 | |
| c.set_progress_handler(count,100) | |
| c.execute(query,args).fetchone() | |
| c.set_progress_handler(None,0) | |
| return {'median_ms':statistics.median(times),'min_ms':min(times),'vm_steps_rounded_100':steps,'plan':[r[3] for r in c.execute('EXPLAIN QUERY PLAN '+query,args)]} | |
| before=measure(q) | |
| c.execute('''CREATE INDEX orchestration_v2_projection_turn_items_failed_error_idx | |
| ON orchestration_v2_projection_turn_items(thread_id,run_id,node_id,updated_at DESC,ordinal DESC,turn_item_id DESC) | |
| WHERE type='error' AND status='failed' ''') | |
| after=measure(q.replace('INDEXED BY orchestration_v2_projection_turn_items_thread_run_idx','')) | |
| r={'fixture_items':50002,'payload_output_bytes':512,'before':before,'after':after} | |
| Path('/tmp/t3-performance-20261012-0VblsN/error-lookup-bench.json').write_text(json.dumps(r,indent=2)) | |
| print(json.dumps(r,indent=2)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment