From 704622cf656096403bfb51be8479b6dc84998935 Mon Sep 17 00:00:00 2001 From: Diego Resendez Date: Mon, 26 Oct 2026 13:23:55 -0500 Subject: [PATCH] bench(compare): add compression cases to the A/B harness The A/B harness had no case with compression on, so a change to the response write path was measured only on its uncompressed branch. Add an 8 KB JSON response uncompressed, identity-negotiated, gzip and br, plus a small response under the threshold with compression enabled. Signed-off-by: Diego Resendez --- bench/compare.ts | 9 +++++++++ bench/servers/compare.ts | 7 +++++++ 2 files changed, 16 insertions(+) diff --git a/bench/compare.ts b/bench/compare.ts index 4b0d46a..4af6ff3 100644 --- a/bench/compare.ts +++ b/bench/compare.ts @@ -75,6 +75,15 @@ const CASES: Case[] = [ // all-static, so it takes the full scan rather than the early exit a literal path gets. { name: 'param, 50 routes', path: '/users/42', env: { GT_ROUTES: '50' } }, { name: 'param, 200 routes', path: '/users/42', env: { GT_ROUTES: '200' } }, + // Compression (CARD-16). `json 8KB uncompressed` is the same response uncompressed, so each compressed case + // has its own baseline in the table. `hello + compression` sits under the threshold: the cost of + // deciding not to encode, which is what most small responses pay once compression is on. Without + // `accept-encoding`, the 8 KB case measures negotiation alone. + { name: 'json 8KB uncompressed', path: '/big' }, + { name: 'hello + compression', path: '/hello', env: { GT_COMPRESS: '1' }, headers: { 'accept-encoding': 'gzip, br' } }, + { name: 'json 8KB + compression, identity', path: '/big', env: { GT_COMPRESS: '1' } }, + { name: 'json 8KB + gzip', path: '/big', env: { GT_COMPRESS: '1' }, headers: { 'accept-encoding': 'gzip' } }, + { name: 'json 8KB + br', path: '/big', env: { GT_COMPRESS: '1' }, headers: { 'accept-encoding': 'br' } }, ]; const ONLY = process.env.AB_ONLY; diff --git a/bench/servers/compare.ts b/bench/servers/compare.ts index 4ba044b..e8f4ac5 100644 --- a/bench/servers/compare.ts +++ b/bench/servers/compare.ts @@ -18,12 +18,17 @@ function makeStep(n: number) { } const steps = [1, 2, 3, 4, 5].map(makeStep); +// ~8 KB of JSON: well over the 1024-byte compression threshold, and repetitive the way list +// responses are, so the encoders do real work rather than bailing out on incompressible input. +const BIG = Array.from({ length: 120 }, (_, i) => ({ id: i, name: `user ${i}`, email: `user${i}@example.com`, active: i % 2 === 0 })); + @Route('/') class Bench { @Get('/hello') hello() { return { hello: 'world' }; } @Get('/users/:id') user(@param('id') id: string) { return { id }; } @Get('/pipeline') pipeline(@needs('s3') s3: number) { return { hello: 'world', s3 }; } @Post('/validate') validate(@body(emailSchema) b: any) { return { email: b.email }; } + @Get('/big') big() { return BIG; } @Get('/steps/5') steps5(@needs('s5') s5: number) { return { hello: 'world', s5 }; } // Reads the counter without resetting it — the read itself carries no Origin, so it cannot // change what it reports. @@ -68,10 +73,12 @@ const cors = } : undefined; +// Only passed when asked for, so the file still boots against a revision without compression. const app = createApp({ modules: [BenchModule], security: process.env.GT_SECURE === '1', ...(cors ? { cors } : {}), + ...(process.env.GT_COMPRESS === '1' ? { compression: true } : {}), }); async function main() {