Skip to content

Benchmarks ​

Compare how fast Golem's generated code parses, stringifies and validates, and what each feature costs.

WARNING

Benchmarks are for reference purposes only.

The page has two tabs.

Speed per payload shows the speed of Golem's three setups on each payload.

What each feature costs compares Golem with itself: validation on and off, IModel and IObject, many converted fields and none, and invalid input and valid input.

Measured 2026-11-30 · Golem 1.2.0 · Node v24.21.0 · Apple M4 · darwin/arm64 · d593a75 + local changes · median ops/s of 8 batches · spread 29.9%

A column is one setup of Golem. Each setup turns JSON text into a value and back.

  • Golem (IObject) uses an IObject declaration. It gives plain objects, checks every rule, rejects unknown properties and converts TSerde fields.
  • Golem (IModel) uses an IModel declaration. It gives instances of the model class, with validation off.
  • Golem (IModel, validated) uses the same declaration with Golem's own generated validators on.
Payload and operationGolem (IObject)Golem (IModel)Golem (IModel, validated)
Simple object 123 B
Parse1,552,734899,310845,847
Stringify5,826,8058,158,3602,701,598
Validate16,690,583does not apply3,785,311
Nested object 817 B
Parse427,420282,303262,790
Stringify892,7271,044,795549,429
Validate5,672,010does not apply1,233,447
Large array 100 KB
Parse3,9582,5852,474
Stringify7,5598,4304,567
Validate62,282does not apply9,830
Checkout 347 B
Parse349,612383,155294,268
Stringify214,137566,853206,733
Validate1,363,907does not apply769,390
Checkout, no conversion 347 B
Parse836,021702,034602,919
Stringify1,283,4631,944,584988,859
Validate4,101,862does not apply2,092,408
  • Each number is operations per second. The bar under it shows the number against the fastest setup in its row.
  • A dash (—) means the setup has no such operation.

Code

Declarations for the Simple object payload ​

ts
export type TPlainPoint3D = IObject<{
  x: number;
  y: number;
  z: number;
}>;
export type TPlainObjectSimple = IObject<{
  scale: TPlainPoint3D;
  position: TPlainPoint3D;
  rotate: TPlainPoint3D;
  pivot: TPlainPoint3D;
}>;
ts
export type TPoint3D = IModel<{
  x: number;
  y: number;
  z: number;
}>;
export class Point3D extends model<TPoint3D>() {}

export type TObjectSimple = IModel<{
  scale: Point3D;
  position: Point3D;
  rotate: Point3D;
  pivot: Point3D;
}>;
export class ObjectSimple extends model<TObjectSimple>() {}

Timed calls ​

ts
const model = ops.parse(input.text);
const timed = {
  'text-to-model': () => ops.parse(input.text),
  'model-to-text': () => ops.stringify(model),
  validate: () => {
    if (!ops.validate(model)) throw new Error('IObject validate rejected a valid fixture');
    return true;
  },
};
ts
// Public v1.2 model class methods (ModelClass.parse, stringify, validate, fromWireFormat, toWireFormat).
fixtures.push({
  name: input.name,
  payload: input.payload,
  operations: {
    'object-to-model': () => ops.fromWireFormat(input.payload, validation),
    'model-to-object': () => ops.toWireFormat(model, validation),
    'text-to-model': () => ops.parse(input.text, validation),
    'model-to-text': () => ops.stringify(model, validation),
    ...(validation ? {
      validate: () => {
        const ok = ops.validate(model);
        if (!ok) throw new Error('Class validate rejected a valid fixture');
        return true;
      },
    } : {}),
  },

Declarations for the Nested object payload ​

ts
export type TPlainConstrainedTimestamp = IObject<{
  time: number;
  zone: number;
}>;
export type TPlainConstrainedAccount = IObject<{
  id: number & Integer & Minimum<1>;
  code: string & MinLength<3>;
  created_at: TPlainConstrainedTimestamp;
}>;
export type TPlainConstrainedEnterprise = IObject<{
  id: number & Integer & Minimum<1>; account: TPlainConstrainedAccount; name: string & MinLength<2>;
  grade: number & Integer & Minimum<1>; created_at: TPlainConstrainedTimestamp;
}>;
export type TPlainConstrainedChannel = IObject<{
  id: number & Integer & Minimum<1>; code: string & MinLength<2> & MaxLength<16> & Pattern<'^[a-z]+$'>; name: string & MinLength<2>;
  sequence: number & Integer & Minimum<1>; exclusive: boolean; priority: number & Integer & Minimum<0>; created_at: TPlainConstrainedTimestamp;
}>;
export type TPlainConstrainedMember = IObject<{
  id: number & Integer & Minimum<1>; account: TPlainConstrainedAccount; enterprise: TPlainConstrainedEnterprise | null;
  emails: (string & MinLength<3>)[] & MinItems<1> & MaxItems<3>; created_at: TPlainConstrainedTimestamp; authorized: boolean;
}>;
export type TPlainConstrainedObjectHierarchical = IObject<{
  id: number & Integer & Minimum<1>; channel: TPlainConstrainedChannel; member: TPlainConstrainedMember | null;
  account: TPlainConstrainedAccount | null; href: string & MinLength<8> & Pattern<'^https://'>;
  referrer: string & MinLength<8> & Pattern<'^https://'>; ip: [number, number, number, number] & MinItems<4> & MaxItems<4>;
  created_at: TPlainConstrainedTimestamp;
}>;
ts
export type TConstrainedTimestamp = IModel<{
  time: number;
  zone: number;
}>;
export class ConstrainedTimestamp extends model<TConstrainedTimestamp>() {}

export type TConstrainedAccount = IModel<{
  id: number & Integer & Minimum<1>;
  code: string & MinLength<3>;
  created_at: ConstrainedTimestamp;
}>;
export class ConstrainedAccount extends model<TConstrainedAccount>() {}

export type TConstrainedEnterprise = IModel<{
  id: number & Integer & Minimum<1>;
  account: ConstrainedAccount;
  name: string & MinLength<2>;
  grade: number & Integer & Minimum<1>;
  created_at: ConstrainedTimestamp;
}>;
export class ConstrainedEnterprise extends model<TConstrainedEnterprise>() {}

export type TConstrainedChannel = IModel<{
  id: number & Integer & Minimum<1>;
  code: string & MinLength<2> & MaxLength<16> & Pattern<'^[a-z]+$'>;
  name: string & MinLength<2>;
  sequence: number & Integer & Minimum<1>;
  exclusive: boolean;
  priority: number & Integer & Minimum<0>;
  created_at: ConstrainedTimestamp;
}>;
export class ConstrainedChannel extends model<TConstrainedChannel>() {}

export type TConstrainedMember = IModel<{
  id: number & Integer & Minimum<1>;
  account: ConstrainedAccount;
  enterprise: ConstrainedEnterprise | null;
  emails: (string & MinLength<3>)[] & MinItems<1> & MaxItems<3>;
  created_at: ConstrainedTimestamp;
  authorized: boolean;
}>;
export class ConstrainedMember extends model<TConstrainedMember>() {}

export type TConstrainedObjectHierarchical = IModel<{
  id: number & Integer & Minimum<1>;
  channel: ConstrainedChannel;
  member: ConstrainedMember | null;
  account: ConstrainedAccount | null;
  href: string & MinLength<8> & Pattern<'^https://'>;
  referrer: string & MinLength<8> & Pattern<'^https://'>;
  ip: [number, number, number, number] & MinItems<4> & MaxItems<4>;
  created_at: ConstrainedTimestamp;
}>;
export class ConstrainedObjectHierarchical extends model<TConstrainedObjectHierarchical>() {}

Timed calls ​

ts
const model = ops.parse(input.text);
const timed = {
  'text-to-model': () => ops.parse(input.text),
  'model-to-text': () => ops.stringify(model),
  validate: () => {
    if (!ops.validate(model)) throw new Error('IObject validate rejected a valid fixture');
    return true;
  },
};
ts
// Public v1.2 model class methods (ModelClass.parse, stringify, validate, fromWireFormat, toWireFormat).
fixtures.push({
  name: input.name,
  payload: input.payload,
  operations: {
    'object-to-model': () => ops.fromWireFormat(input.payload, validation),
    'model-to-object': () => ops.toWireFormat(model, validation),
    'text-to-model': () => ops.parse(input.text, validation),
    'model-to-text': () => ops.stringify(model, validation),
    ...(validation ? {
      validate: () => {
        const ok = ops.validate(model);
        if (!ok) throw new Error('Class validate rejected a valid fixture');
        return true;
      },
    } : {}),
  },

Declarations for the Large array payload ​

ts
export type TPlainTimestamp = IObject<{
  time: number;
  zone: number;
}>;
export type TPlainEmployee = IObject<{
  id: number;
  name: string;
  age: number;
  grade: number;
  employed_at: TPlainTimestamp;
}>;
export type TPlainDepartment = IObject<{
  id: number;
  code: string;
  sales: number;
  created_at: TPlainTimestamp;
  employees: TPlainEmployee[];
}>;
export type TPlainCompany = IObject<{
  id: number;
  serial: number;
  name: string;
  established_at: TPlainTimestamp;
  departments: TPlainDepartment[];
}>;
export type TPlainCollection = IObject<{
  data: TPlainCompany[];
}>;
ts
export type TTimestamp = IModel<{
  time: number;
  zone: number;
}>;
export class Timestamp extends model<TTimestamp>() {}

export type TEmployee = IModel<{
  id: number;
  name: string;
  age: number;
  grade: number;
  employed_at: Timestamp;
}>;
export class Employee extends model<TEmployee>() {}

export type TDepartment = IModel<{
  id: number;
  code: string;
  sales: number;
  created_at: Timestamp;
  employees: Employee[];
}>;
export class Department extends model<TDepartment>() {}

export type TCompany = IModel<{
  id: number;
  serial: number;
  name: string;
  established_at: Timestamp;
  departments: Department[];
}>;
export class Company extends model<TCompany>() {}

export type TCollection = IModel<{
  data: Company[];
}>;
export class Collection extends model<TCollection>() {}

Timed calls ​

ts
const model = ops.parse(input.text);
const timed = {
  'text-to-model': () => ops.parse(input.text),
  'model-to-text': () => ops.stringify(model),
  validate: () => {
    if (!ops.validate(model)) throw new Error('IObject validate rejected a valid fixture');
    return true;
  },
};
ts
// Public v1.2 model class methods (ModelClass.parse, stringify, validate, fromWireFormat, toWireFormat).
fixtures.push({
  name: input.name,
  payload: input.payload,
  operations: {
    'object-to-model': () => ops.fromWireFormat(input.payload, validation),
    'model-to-object': () => ops.toWireFormat(model, validation),
    'text-to-model': () => ops.parse(input.text, validation),
    'model-to-text': () => ops.stringify(model, validation),
    ...(validation ? {
      validate: () => {
        const ok = ops.validate(model);
        if (!ok) throw new Error('Class validate rejected a valid fixture');
        return true;
      },
    } : {}),
  },

Declarations for the Checkout payload ​

ts
export type TJsonLineItem = IObject<{
  sku: string & MinLength<3>;
  quantity: number & Integer & Minimum<0>;
  price: number & Minimum<0>;
}>;

export type TJsonCheckout = IObject<{
  money: PaymentMoney & TValidation<typeof extraMoney>;
  note: string & TValidation<typeof notBlank>;
  code: number & TValidation<typeof positive> & TSerde<typeof encodeHex, typeof decodeHex>;
  when: Date;
  items: Array<{ sku: string & MinLength<3> }>;
  primary: TJsonLineItem;
  flags: Record<string, string>;
  channel: ({ kind: 'open' } | { kind: 'hold'; until: Date }) & Discriminator<'kind'>;
  span: [Date, Date];
  hold: Date | null;
  bag?: { lane: string };
  memo?: string;
}>;
ts
export type TLineItem = IModel<{
  sku: string & MinLength<3>;
  quantity: number & Integer & Minimum<0>;
  price: number & Minimum<0>;
}>;
export class LineItem extends model<TLineItem>() {}

export type TCheckout = IModel<{
  money: PaymentMoney & TValidation<typeof extraMoney>;
  note: string & TValidation<typeof notBlank>;
  code: number & TValidation<typeof positive> & TSerde<typeof encodeHex, typeof decodeHex>;
  when: Date;
  items: Array<{ sku: string & MinLength<3> }>;
  primary: LineItem;
  flags: Record<string, string>;
  channel: ({ kind: 'open' } | { kind: 'hold'; until: Date }) & Discriminator<'kind'>;
  span: [Date, Date];
  hold: Date | null;
  bag?: { lane: string };
  memo?: string;
}>;
export class Checkout extends model<TCheckout>() {}

Timed calls ​

ts
const model = parse<TJsonCheckout>(input.text);
const timed = {
  'text-to-model': () => parse<TJsonCheckout>(input.text),
  'model-to-text': () => stringify<TJsonCheckout>(model),
  validate: () => {
    if (!validate<TJsonCheckout>(model)) throw new Error('IObject validate rejected a valid fixture');
    return true;
  },
};
ts
const options = validation ? undefined : VALIDATE_OFF;
const decode = (): Checkout => Checkout.fromWireFormat(input.payload, options);
const model = decode();
const fixture = featureComparison(input.name, input.payload, {
  'object-to-model': decode,
  'model-to-object': () => Checkout.toWireFormat(model, options),
  'text-to-model': () => Checkout.parse(input.text, options),
  'model-to-text': () => Checkout.stringify(model, options),
  ...(validation ? {
    validate: () => {
      if (!Checkout.validate(model)) throw new Error('Class validate rejected a valid fixture');
      return true;
    },
  } : {}),

Declarations for the Checkout, no conversion payload ​

ts
// Stamp is `string & Format<'date-time'>`: dates stay strings, and nothing converts.
export type TJsonCheckoutPlain = IObject<{
  money: { amount: number & Minimum<0>; currency: string & Pattern<'^[A-Z]{3}$'> };
  note: string & MinLength<1>;
  code: string & Pattern<'^[0-9a-f]+$'>;
  when: Stamp;
  items: Array<{ sku: string & MinLength<3> }>;
  primary: TJsonLineItem;
  flags: Record<string, string>;
  channel: ({ kind: 'open' } | { kind: 'hold'; until: Stamp }) & Discriminator<'kind'>;
  span: [Stamp, Stamp];
  hold: Stamp | null;
  bag?: { lane: string };
  memo?: string;
}>;
ts
// LineItem is declared with the Checkout payload. Stamp is `string & Format<'date-time'>`: dates stay strings, and nothing converts.
export type TCheckoutPlain = IModel<{
  money: { amount: number & Minimum<0>; currency: string & Pattern<'^[A-Z]{3}$'> };
  note: string & MinLength<1>;
  code: string & Pattern<'^[0-9a-f]+$'>;
  when: Stamp;
  items: Array<{ sku: string & MinLength<3> }>;
  primary: LineItem;
  flags: Record<string, string>;
  channel: ({ kind: 'open' } | { kind: 'hold'; until: Stamp }) & Discriminator<'kind'>;
  span: [Stamp, Stamp];
  hold: Stamp | null;
  bag?: { lane: string };
  memo?: string;
}>;
export class CheckoutPlain extends model<TCheckoutPlain>() {}

Timed calls ​

ts
const model = parse<TJsonCheckoutPlain>(input.text);
const timed = {
  'text-to-model': () => parse<TJsonCheckoutPlain>(input.text),
  'model-to-text': () => stringify<TJsonCheckoutPlain>(model),
  validate: () => {
    if (!validate<TJsonCheckoutPlain>(model)) throw new Error('IObject validate rejected a valid fixture');
    return true;
  },
};
ts
const options = validation ? undefined : VALIDATE_OFF;
const model = CheckoutPlain.fromWireFormat(input.payload, options);
const timed = {
  'object-to-model': () => CheckoutPlain.fromWireFormat(input.payload, options),
  'model-to-object': () => CheckoutPlain.toWireFormat(model, options),
  'text-to-model': () => CheckoutPlain.parse(input.text, options),
  'model-to-text': () => CheckoutPlain.stringify(model, options),
  ...(validation ? {
    validate: () => {
      if (!CheckoutPlain.validate(model)) throw new Error('Class validate rejected a valid fixture');
      return true;
    },
  } : {}),
};
  • Simple object (123 B): Four 3D points. Measures per-call overhead. Source
  • Nested object (817 B): A nested API record with integer, length, pattern and array-size constraints. Source
  • Large array (100 KB): One company, 10 departments, 1,000 employees. Source
  • Checkout (347 B): Money from a generated SDK type, hex code, dates, nested line items, flags, a union and optional fields, with value conversion. Source
  • Checkout, no conversion (347 B): The checkout fields with dates as date-time strings, no value conversion and no custom rule. It keeps the union, the tuple, the map and the optional and nullable fields. Source

Against hand-written code ​

Hand-written code copies each field and converts each date, and checks nothing. The table shows Golem's speed with validation on as a fraction of that code's speed, so 1.00 means equal. Golem checks the value before and after each conversion. Parse is JSON.parse then the hand-written decode; stringify is the hand-written encode then JSON.stringify.

ModelDecodeEncodeParseStringify
Flat0.460.890.731.09
Nested0.360.800.810.95
Union0.280.770.551.02
Array of 100 items0.460.920.730.90
Tuple0.400.910.640.95
Optional fields0.530.930.741.04

They are point-in-time v1.2.0 snapshots measured with npm run bench:handwritten. Golem uses a generated JSON string writer for stringify, while the hand-written baseline calls JSON.stringify without validation. Run npm run bench:handwritten to reproduce them on your machine.

Split SDK bundle size and build speed ​

These figures are point-in-time v1.2.0 snapshots reproducible via npm run bench:extras, which measures three extra dimensions on your machine:

  • Split SDK validator bundle size (minified and gzipped with esbuild): one split standalone operation validator vs the full 5-operation SDK, Zod, and Ajv. On Golem 1.2.0, one split validator bundles to 5.09 KB gzip (vs 20.1 KB for the full 5-operation SDK, 38.6 KB for Ajv, and 92.7 KB for Zod).
  • Full error collection (failFast: false): Golem's single-pass full validator vs Zod, Ajv (allErrors: true), and class-validator (stopAtFirstError: false).
  • Direct TypeScript-to-IR generation speed: wall time and emitted size across 10, 50, and 100 models (100 models generate in ~354 ms).

What is measured ​

A case is one payload, one operation and one setup. The tables show the median speed of a case in operations per second. The payloads differ in what they convert:

PayloadWhat it converts
Simple objectNothing
Nested objectNothing
Large arrayNothing
CheckoutA few fields: money, a hex code and dates
Checkout, no conversionNothing
Serde noneNothing, in 21 fields
Serde manyEvery one of the same 21 fields
Union, taggedOne date in each of 100 events
Union, class-firstOne date in each of 100 events
Temporal fieldsAll 20 fields, with the temporal-polyfill package as Temporal
Recursive modelEach of 106 nodes to its class
Unique stringsNothing. Validate compares 1,000 strings
Unique objectsNothing. Validate compares 100 objects
Unique small listNothing. Validate compares 3 objects
Unique nested objectsNothing. Validate compares 20 objects that differ only in a nested field
Nest querySix query strings to their declared types
Client callThe request body and the response of one generated client call

The speed tab shows the first five payloads. The cost tab shows every payload. Nest query shows the Decode row only. Client call shows the Call row only: it runs the generated client against a stub fetch that builds a new Response, so its time includes that Response and no network.

The run is short, so read the ratios between setups in one run and not the absolute numbers. Do not compare numbers from two machines or from two runs.

  1. The same JSON text. Every setup gets the same JSON text for a case and parses it in its own way.
  2. Proof before timing. Each setup must turn its parsed value back into the original JSON. A setup that validates must reject each invalid variant of the payload. A setup that fails gets no number. These checks run in a separate process.
  3. One process for each setup, valid input only. Each setup is timed in its own process, on valid input only. A validator runs slower after it has rejected differently shaped input, because V8 optimizes its generated function again for the new object shapes. The cost tab times invalid input in a separate process.
  4. A rotated order. The run has four interleaved rounds with balanced rotation across setups. In each round a case is warmed up for 200 ms and then timed in two batches of 100 ms, so the table shows the median of eight batches.
  5. Every result is consumed. A checksum reads each result, so the engine cannot remove the timed call.
  6. The spread is recorded. Each case stores its minimum, median and maximum.

What each feature costs ​

Each ratio on the second tab divides one speed by another speed, for the same operation on the same payload. A ratio below 1.00x means that the first speed is lower.

  • on/off divides the speed with validation on by the speed with validation off. It is shown for IModel and for IObject. Off is a build with validation off. Validate has no off mode.
  • IModel/IObject divides the IModel speed by the IObject speed, with validation on in both.
  • serde many/none divides the speed on Serde many by the speed on Serde none, with validation on. It is shown on the Serde many rows only.
  • invalid/valid divides the speed on one invalid value by the speed on a valid value, with validation on. It is shown for parse, decode and validate. Golem makes the path of a valid value fast, and the path of an invalid value builds the error and can be slower.

A dash means that the pair does not apply. "Not run" means that the run did not time the pair. The tab has no release column.

Run the benchmarks ​

Reproduce one number on your machine. Name one setup and one payload:

bash
npm run bench -- --adapters golem-object --payloads simple
  • The payloads are simple, nested, array, checkout, checkout-plain, serde-none, serde-many, union-tagged, union-class, temporal, recursive, unique-strings, unique-objects, unique-small, unique-nested, nest-query and client-call.
  • The run prints its tables to the console and writes scripts/benchmark/results.json for full runs (filtered runs write .cache/benchmark/results.json).
  • A name that is not valid stops the run before it starts, with exit code 2. The message lists the valid names.
  • The run stores the machine load with the numbers, so stop other work on the machine first.