Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions packages/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"check:api-boundaries": "node scripts/check-api-boundaries.mjs",
"test": "vitest run",
"deploy": "wrangler deploy",
"benchmark:loading": "vitest run --config scripts/loading-baseline.config.ts",
"db:migrate": "node scripts/migrate.mjs",
"db:verify": "node scripts/verify-schema.mjs",
"db:studio": "drizzle-kit studio --config drizzle.config.ts",
Expand Down Expand Up @@ -38,6 +39,7 @@
"ajv": "^8.20.0",
"drizzle-kit": "^0.31.10",
"happy-dom": "^20.14.5",
"playwright": "^1.64.0",
"tailwindcss": "^4.1.14",
"tsx": "^4.23.15",
"typescript": "^5.9.3",
Expand Down
46 changes: 46 additions & 0 deletions packages/app/performance/GEN-2154.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# GEN-2154 loading measurements

Measured October 9, 2026. Before: default-branch commit `daf766e`; after: this branch. Both use the same ten-job fixture (two ordered triggers each, three run states, Exe/Amp/Tail connections), PostgreSQL 16.15, Node 22.20, headless Chromium 156, and five sequential samples per screen. The before and after suites ran sequentially on the same VM. Each query has an injected 20 ms delay to expose serial dependency costs. Normal pool settings (`max=5`, `maxUses=1`) remain in force. These are controlled local results, **not production latency estimates or p95**.

The browser uses an actual signed session cookie, receives the authenticated Worker-generated HTML, runs its scripts and renders local CSS. Playwright intercepts HTTP and dispatches to the Worker entrypoint with the browser's cookie. It excludes internet transit, Cloudflare scheduling, Hyperdrive/Neon network latency, and real OAuth-provider transport. The only provider stub forwards HTML routes and supplies an empty authorized-client list; API authentication and PostgreSQL repositories are real. Navigation starts before the shell's membership lookup. Useful content means a populated Jobs list, job/run heading, loaded target choices in the editor, installed integration cards, or the completed empty API-key list. Endpoint timings include complete JSON response consumption. Job create measures execution-target latency; job edit measures job detail; the full browser measurements include their other concurrent requests.

| Screen | Endpoint median ms (before → after) | Navigation to useful content median ms (before → after) |
| -- | -- | -- |
| Jobs | 174.1 → 106.4 | 264.4 → 260.4 |
| Job detail | 127.8 → 98.4 | 287.2 → 201.6 |
| Run detail | 179.2 → 80.1 | 868 → 175.2 |
| Job create | 123.2 → 49.5 | 305.6 → 265.6 |
| Job edit | 118.5 → 96.4 | 300.8 → 196.1 |
| Integrations | 280.3 → 51.3 | 378.8 → 160.5 |
| API Keys | 74.2 → 47.1 | 185.4 → 122.3 |

Raw samples' median/range summaries, indexes, and local `EXPLAIN (ANALYZE, BUFFERS)` plans are in `gen-2154-before.json` and `gen-2154-after.json`. Browser scheduling contributes visible variance, particularly for run and editor pages; do not infer fixed per-page savings from five samples. For example, before-run useful-content samples ranged from 376.6–883.2 ms, while Jobs useful-content medians changed only 264.4→260.4 ms despite lower endpoint latency. Those browser results should not be treated as stable savings.

## Repeat the cookie baseline

Use a **disposable local PostgreSQL server** whose user can create/drop databases. The fixture creates an isolated database, applies all migrations, and removes it after the suite. Never point this at production.

```sh
npm ci
npm exec --workspace=factorize -- playwright install chromium
AUTH_TEST_DATABASE_URL=postgresql://postgres@localhost:5432/postgres \
LOADING_QUERY_DELAY_MS=20 \
LOADING_REPORT_PATH=/tmp/loading.json \
npm run benchmark:loading --workspace=factorize
```

For the old code, copy `test/helpers/loading-fixture.ts`, `test/loading-baseline.e2e.test.ts`, and `scripts/loading-baseline.config.ts` into a disposable checkout of `daf766e`, share/install the same dependencies, and run `vitest run --config scripts/loading-baseline.config.ts` in `packages/app`. Run the two suites sequentially. Set query delay to zero for an additional local execution-only baseline; that still cannot measure Cloudflare socket ownership or Hyperdrive connection setup.

## Production comparison and remaining costs

`gen-2154-proxy-baseline.jsonl` contains a fresh five-request sequential **integration-authenticated** production baseline. All measured API reads returned 200 except API Keys, which returned the expected 403 because that endpoint requires an interactive owner session. HTML through this proxy returns a sign-in shell. Those observations are separate from the cookie baseline above. This branch was not deployed, so there is no production after measurement. Repeat browser and cookie API measurements after rollout with a normal signed-in owner browser; use DevTools Network/Performance to measure navigation through the first populated content and save endpoint `Server-Timing` along with total latency for the same pages, same tenant, and same records. Warm once, measure at least five sequential navigations/requests, then expand the sample before considering tail latency.

`Server-Timing` now separates authoritative service membership/token validation (`auth`) from the remaining application phase (`application`, including data reads, validation, decryption, serialization and rendering). HTML shell responses use the same phases. These durations are wall-clock phases, not summed per-query time. Cookie signature/expiry checks and upstream bearer-provider authentication happen before the protected API timer; network transit and deferred tasks are excluded.

Jobs now use one jobs query, one ordered trigger query, and one grouped statistics query, instead of `1 + 2N` data queries. Prompts, trigger configs and existing response fields remain available for API compatibility. Integration status uses one filtered encrypted-connection read and one grouped Tail reference-count read; execution targets also use a single filtered connection read. Run metadata reads start together after tenant-scoped run existence is confirmed. A tenant-qualified join supplies `job_name`, so run rendering and trace loading no longer wait for a full job request. Live polling behavior remains unchanged.

The local plans contain only three historical run rows: the old aggregate executed in 0.146 ms in the before fixture; the new ten-job batch executed in 0.095 ms in the after fixture. Both used the tenant-prefix bitmap index scan, with no disk sort spill. The batch replaces per-job round trips and full state arrays; these tiny plans do **not** establish a production index bottleneck or faster SQL execution. The checked-in schema has tenant primary/unique indexes and scheduler partial indexes, but no job-specific history-order index. For large production histories, obtain a read-only production plan and row/cardinality statistics before considering `(tenant_id, job_id, created_at DESC, id DESC)` and a partial active-state index. The batch still scans historical rows for counts/latest selection and materializes a CTE; that remains a scaling cost to measure.

`databaseFor()` still constructs per-call request-local pools and retires checkouts with `maxUses=1`. Batching directly reduces checkouts. The prior #163 isolation constraint still applies: sharing a module-global Pool can exchange request-owned sockets even with `maxUses=1`. This local test cannot measure Hyperdrive setup cost; a request-scoped reusable pool with guaranteed cleanup needs a separate Worker canary (including overlapping requests and background work) before changing socket lifecycle. No upstream-connection savings are claimed.

Worker placement and query caching remain unchanged. Neon us-west-2 plus unconfigured placement are hypotheses, not measured causes. Compare identical cookie requests and Server-Timing on a placement canary before choosing placement. Authorization and mutable run state must stay uncached. The shell→API dependency remains; initial-data rendering can be evaluated once production backend phases are understood.
Loading
Loading