← tests

json

Serialising a body the framework already holds, across three size regimes.

Comparable across every framework at one size, and across the three sizes as a set. The small row against the large one is what separates a framework with a fast codec from one with a fast request path.

testheftrequestbasewhat differs from the base
json.small1GET /json/small
json.large4GET /json/largejson.smalla larger response body, same route and same handler
json.medium2GET /json/mediumjson.smalla larger response body, same route and same handler

json.small

heft 1

base of authorized.allowed, cache.small, compressed.identity_small, cors.request, etag.small, json.large, json.medium, middleware.none, parameters.static, query.one, static.small, template.small

One row out, serialised from a body the framework already holds. The plainest question in the corpus once something has to be serialised. Read against baseline.plaintext, the difference is the codec.

Request

GET /json/small

No body.

Expected response

HTTP 200

payload items.small

{"size":"small","count":1,"items":[{"id":1,"name":"slate-lamp-6647","category":"tools","priceCents":18928,"inStock":true}]}

Compared as parsed JSON, so key order and how a number is written do not matter.

Test source, tests/json/small.ts
tests/json/small.tsopen on GitHub →
import { performanceTest } from "#kit";
import { items } from "#payloads";

const path = "/json/small";

export default performanceTest({
  id: { family: "json", name: "small" },
  path,
  heft: 1,
  about:
    "One row out, serialised from a body the framework already holds. The " +
    "plainest question in the corpus once something has to be serialised. " +
    "Read against baseline.plaintext, the difference is the codec.",

  request: (c) => c.get(path).okWith(items.small),
});

json.large

heft 4

base json.smallbase of cache.large, compressed.identity_large, etag.large, static.large, template.large

Fourteen hundred rows out, serialised from a body the framework already holds. The size at which the writer stops being free. Read against json.small, the pair is what separates a framework with a fast codec from one with a fast request path.

Request

GET /json/large

No body.

Expected response

HTTP 200

payload items.large

{"size":"large","count":1425,"items":[{"id":1,"name":"slate-lamp-6647","category":"tools","priceCents":18928,"inStock":true},{"id":2,"name":"brass-hinge-5716","category":"garden","priceCents":17577,"inStock":true},{"id":3,"name":"linen-ring-6971","category":"kitchen","priceCents":5540,"inStock":true},{"id":4,"name":"copper-bolt-9217","category":"outdoor","priceCents":11562,"inStock":true},{"id":5,"name":"linen-lamp-8288","category":"office","priceCents":1413,"inStock":true},{"id":6,"name":"copper-pan-9308","category":"tools","priceCents":10795,"inStock":true},{"id":7,"name":"slate-seed-3051","category":"garden","priceCents":9667,"inStock":false},{"id":8,"name":"oak-lamp-8662","category":"kit
… 128,510 bytes total

Compared as parsed JSON, so key order and how a number is written do not matter.

Test source, tests/json/large.ts
tests/json/large.tsopen on GitHub →
import { performanceTest } from "#kit";
import { items } from "#payloads";

const path = "/json/large";

export default performanceTest({
  id: { family: "json", name: "large" },
  path,
  base: "json.small",
  varies: "size",
  heft: 4,
  about:
    "Fourteen hundred rows out, serialised from a body the framework already " +
    "holds. The size at which the writer stops being free. Read against " +
    "json.small, the pair is what separates a framework with a fast codec " +
    "from one with a fast request path.",

  request: (c) => c.get(path).okWith(items.large),
});

json.medium

heft 2

base json.smallbase of cache.medium, static.medium, stream.ndjson, template.medium

Eighty-nine rows out, serialised from a body the framework already holds. The middle size, where the codec is doing real work and the response still fits a single write. Read against json.small rather than on its own.

Request

GET /json/medium

No body.

Expected response

HTTP 200

payload items.medium

{"size":"medium","count":89,"items":[{"id":1,"name":"slate-lamp-6647","category":"tools","priceCents":18928,"inStock":true},{"id":2,"name":"brass-hinge-5716","category":"garden","priceCents":17577,"inStock":true},{"id":3,"name":"linen-ring-6971","category":"kitchen","priceCents":5540,"inStock":true},{"id":4,"name":"copper-bolt-9217","category":"outdoor","priceCents":11562,"inStock":true},{"id":5,"name":"linen-lamp-8288","category":"office","priceCents":1413,"inStock":true},{"id":6,"name":"copper-pan-9308","category":"tools","priceCents":10795,"inStock":true},{"id":7,"name":"slate-seed-3051","category":"garden","priceCents":9667,"inStock":false},{"id":8,"name":"oak-lamp-8662","category":"kitc
… 7,953 bytes total

Compared as parsed JSON, so key order and how a number is written do not matter.

Test source, tests/json/medium.ts
tests/json/medium.tsopen on GitHub →
import { performanceTest } from "#kit";
import { items } from "#payloads";

const path = "/json/medium";

export default performanceTest({
  id: { family: "json", name: "medium" },
  path,
  base: "json.small",
  varies: "size",
  heft: 2,
  about:
    "Eighty-nine rows out, serialised from a body the framework already " +
    "holds. The middle size, where the codec is doing real work and the " +
    "response still fits a single write. Read against json.small rather than " +
    "on its own.",

  request: (c) => c.get(path).okWith(items.medium),
});