docs: measure the runtime and the generated client modules
Quality / quality (ubuntu-latest) (push) Failing after 13m21s
Quality / quality (windows-latest) (push) Canceled after 0s

Adds a per-subsystem measurement of reactive.js, made by minifying it
repeatedly with one subsystem removed rather than counting source bytes.

This corrects the earlier audit on both figures and on the conclusion drawn
from them. Component controllers are 23,722 bytes minified / 6,660 gzipped --
30.6% of transfer, not the "about 18%" previously claimed -- and splitting them
out saves 6.6 kB gzipped on a typical page, not "3-4 kB". Measured against the
example app, / and /login use none of the ten controllers and /layout uses one,
so most pages download and parse the lot for nothing.

The larger finding is that the runtime is not where the weight is. One page
parses 490,212 decoded bytes across 11 generated client modules while
transferring 21,026, and the largest module is 89.8% duplicated lines: the
state-restore prologue appears 162 times because client-codegen.ts inlines the
sync into every peer alias of every client function. Gzip hides it on the wire,
but parse cost follows decoded bytes.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
2026-08-09 10:02:36 +05:30
co-authored by Claude Opus 5
parent 30d1632252
commit 5112cc1a62
20 changed files with 643 additions and 5 deletions
+5 -1
View File
@@ -66,7 +66,11 @@ export function serviceClient<Procedures extends AnyProcedures>(
const callPromise = options.transport.call(
{ app, service: contract.name, procedure: property },
input,
{ signal: controller.signal, ...(identity ? { identity } : {}) },
{
signal: controller.signal,
idempotent: contract.procedures[property as keyof Procedures].idempotent === true,
...(identity ? { identity } : {}),
},
);
try {
const result = await Promise.race([callPromise, timeout]);
+8 -2
View File
@@ -31,8 +31,14 @@ export {
} from "./identity.ts";
export type { ExportOptions, ImportOptions, SubjectContext } from "./identity.ts";
export { inProcessTransport } from "./transport.ts";
export type { CallOptions, InProcessHandler, RpcTarget, Transport } from "./transport.ts";
export { inProcessTransport, retryingTransport } from "./transport.ts";
export type {
CallOptions,
InProcessHandler,
RetryTransportOptions,
RpcTarget,
Transport,
} from "./transport.ts";
export { implement } from "./server.ts";
export type {
HandlerContext,
+84
View File
@@ -10,12 +10,96 @@ export interface RpcTarget {
export interface CallOptions {
signal?: AbortSignal;
identity?: string;
/** Supplied from the declared procedure; only these calls may be retried. */
idempotent?: boolean;
}
export interface Transport {
call(target: RpcTarget, payload: unknown, options: CallOptions): Promise<ServiceResult>;
}
export interface RetryTransportOptions {
/** Retries after the initial attempt. Default: 2. */
retries?: number;
/** Initial exponential-backoff delay in milliseconds. Default: 50. */
backoffMs?: number;
/** Consecutive retryable failures before the target circuit opens. Default: 3. */
circuitFailureThreshold?: number;
/** How long an open circuit rejects calls before one probe is allowed. Default: 5s. */
circuitCooldownMs?: number;
now?: () => number;
sleep?: (ms: number, signal?: AbortSignal) => Promise<void>;
}
function targetKey(target: RpcTarget): string {
return `${target.app}/${target.service}/${target.procedure}`;
}
function defaultSleep(ms: number, signal?: AbortSignal): Promise<void> {
return new Promise((resolve) => {
const timer = setTimeout(resolve, ms);
signal?.addEventListener(
"abort",
() => {
clearTimeout(timer);
resolve();
},
{ once: true },
);
});
}
/**
* Add bounded retry and a per-procedure circuit breaker to any transport.
* The idempotency bit comes from the contract and is not caller-controlled.
*/
export function retryingTransport(base: Transport, options: RetryTransportOptions = {}): Transport {
const retries = options.retries ?? 2;
const backoffMs = options.backoffMs ?? 50;
const threshold = options.circuitFailureThreshold ?? 3;
const cooldownMs = options.circuitCooldownMs ?? 5_000;
const now = options.now ?? Date.now;
const sleep = options.sleep ?? defaultSleep;
if (!Number.isInteger(retries) || retries < 0)
throw new RangeError("rpc retries must be a non-negative integer");
if (!Number.isFinite(backoffMs) || backoffMs < 0)
throw new RangeError("rpc backoffMs must be non-negative");
if (!Number.isInteger(threshold) || threshold < 1)
throw new RangeError("rpc circuitFailureThreshold must be positive");
if (!Number.isFinite(cooldownMs) || cooldownMs < 1)
throw new RangeError("rpc circuitCooldownMs must be positive");
const circuits = new Map<string, { failures: number; openUntil: number }>();
return {
async call(target, payload, callOptions) {
const key = targetKey(target);
const circuit = circuits.get(key);
if (circuit && circuit.openUntil > now()) {
return failure(RPC_ERROR_CODES.transport, "Service temporarily unavailable");
}
if (circuit?.openUntil) circuits.delete(key); // cooldown: allow one probe
const attempts = callOptions.idempotent ? retries + 1 : 1;
let result: ServiceResult = failure(RPC_ERROR_CODES.transport, "Service unreachable");
for (let attempt = 0; attempt < attempts; attempt++) {
if (callOptions.signal?.aborted) return failure(RPC_ERROR_CODES.transport, "Call aborted");
result = await base.call(target, payload, callOptions);
if (result.ok || !result.retryable) {
if (result.ok) circuits.delete(key);
return result;
}
if (attempt + 1 < attempts) await sleep(backoffMs * 2 ** attempt, callOptions.signal);
}
const failures = (circuits.get(key)?.failures ?? 0) + 1;
circuits.set(key, {
failures,
openUntil: failures >= threshold ? now() + cooldownMs : 0,
});
return result;
},
};
}
export type InProcessHandler = (
payload: unknown,
identity?: string,