Per-layer dispatch cost at zero, four and sixteen no-op layers.
Comparable across every framework. Every layer calls the next and does nothing else, so the slope between the three is the framework's per-layer cost and nothing else.
| test | heft | request | base | what differs from the base |
|---|---|---|---|---|
| middleware.none | 1 | GET /middleware/none | json.small | a different route carrying the same handler, which should cost nothing |
| middleware.four | 1 | GET /middleware/four | middleware.none | more no-op middleware layers in front of the handler |
| middleware.sixteen | 1 | GET /middleware/sixteen | middleware.none | more no-op middleware layers in front of the handler |
No layers in front of a handler that serialises the small payload. A different route carrying the same handler, which should cost nothing. It is the zero point the other two are read against, and a framework where this differs from json.small is paying for the route rather than the layers.
GET /middleware/none
No body.
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.
import { performanceTest } from "#kit";
import { items } from "#payloads";
const path = "/middleware/none";
export default performanceTest({
id: { family: "middleware", name: "none" },
path,
base: "json.small",
varies: "route",
heft: 1,
about:
"No layers in front of a handler that serialises the small payload. A " +
"different route carrying the same handler, which should cost nothing. It " +
"is the zero point the other two are read against, and a framework where " +
"this differs from json.small is paying for the route rather than the " +
"layers.",
request: (c) => c.get(path).okWith(items.small),
});
Four no-op layers in front of a handler that serialises the small payload. Four layers in front of the handler, each calling the next and doing nothing else. Read against middleware.none, the difference divided by four is the framework's per-layer cost.
GET /middleware/four
No body.
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.
import { performanceTest } from "#kit";
import { items } from "#payloads";
const path = "/middleware/four";
export default performanceTest({
id: { family: "middleware", name: "four" },
path,
base: "middleware.none",
varies: "layers",
heft: 1,
about:
"Four no-op layers in front of a handler that serialises the small " +
"payload. Four layers in front of the handler, each calling the next and " +
"doing nothing else. Read against middleware.none, the difference divided " +
"by four is the framework's per-layer cost.",
request: (c) => c.get(path).okWith(items.small),
});
Sixteen no-op layers in front of a handler that serialises the small payload. Sixteen layers, which is where a per-layer cost that looked like noise at four becomes readable. Read against middleware.none, and against middleware.four to see whether the cost is linear.
GET /middleware/sixteen
No body.
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.
import { performanceTest } from "#kit";
import { items } from "#payloads";
const path = "/middleware/sixteen";
export default performanceTest({
id: { family: "middleware", name: "sixteen" },
path,
base: "middleware.none",
varies: "layers",
heft: 1,
about:
"Sixteen no-op layers in front of a handler that serialises the small " +
"payload. Sixteen layers, which is where a per-layer cost that looked " +
"like noise at four becomes readable. Read against middleware.none, and " +
"against middleware.four to see whether the cost is linear.",
request: (c) => c.get(path).okWith(items.small),
});