Skip to content

03Concepts

Tree-shaking

One module per operation, and what that costs in bytes, measured on every build.

A client generated from a large API should cost an application only the operations it calls. swaggerz gets there by construction rather than by configuration:

  • One module per operation and per model. Each has only static imports and no top-level side effects. The one exception, the default client instance, is marked /* @__PURE__ */.
  • No registry. There is no class per tag and no table of all endpoints that would keep every operation alive.
  • Optional parts are separate modules. Hooks, schemas and the retry() and refreshAuth() middleware are only bundled when imported; with validation off, nothing imports the validation library.

The tree-shaking test generates a client from a synthetic specification and bundles small applications with esbuild, Rollup, Vite and webpack. It asserts which operations each bundle contains (only the imported ones); the sizes below are what it measured for this build of the site.

A client of 1,000 operations and 602 models; minified, not gzipped.
BundleSize
1 operation, direct module import (esbuild)16.1 kB
3 operations through the barrel (esbuild)16.5 kB
3 operations through the barrel (Vite production build)21.4 kB
3 operations through the barrel (webpack production build)16.7 kB
3 operations through the barrel (Rollup, not minified)51.0 kB
1 React Query hook, without TanStack Query itself (esbuild)16.6 kB
The whole client (esbuild)336.7 kB

Measured on 25 October 2026, AMD EPYC 7763 64-Core Processor, Node.js 24.21.0, Linux (x64), at 7dbced4.

The base is the shared runtime: serialization, errors, the client and the transport. Each further operation adds about 217 bytes (the difference between the first two rows, per operation). Model types cost nothing at runtime.

Importing from the barrel (./generated/api) is as tree-shakeable as importing the modules directly: the test bundles through the barrel with esbuild, Rollup, Vite and webpack. webpack removes the unused exports of these side-effect-free modules in production mode, with its usedExports analysis and its minifier.

  • The sizes are minified, not compressed; transfer sizes over the network are smaller.
  • Every client carries its own runtime, so an application that imports two generated clients bundles it twice.