Originally discussed on Discord
The @ag-ui/core & @ag-ui/client use Zod for schema validation.
By default, and in v3, it is not tree-shakeable, meaning terser & bundler cannot easily remove unused code coming from zod.
To solve this, Zod introduced a new "flavour" of Zod in its v4, Zod Mini (See release announcement
In louis-bompart/ag-ui#4, I did the experiment of updating Zod to 3 & shifting all use from Zod "classic" to Zod Mini.
This resulted in a reduction of ~84kb uncompressed, which I estimate represents a ~22% improvement for the bundle size of a very simple HTTPAgent.
To note, numbers are less impressive in a more realistic scenario where the output is gzipped; we shave only 8kb (which still represents a ~13% improvement for the bundle size)
louis-bompart/ag-ui#4 represents the change I'd propose (I'll open a PR upstream with this diff later today).
Attached are two metafiles generated by esbuild with my MRE, to help visualize the bundle size changes with https://esbuild.github.io/analyze/
zod-mini.json
baseline.json
Originally discussed on Discord
The
@ag-ui/core&@ag-ui/clientuse Zod for schema validation.By default, and in v3, it is not tree-shakeable, meaning terser & bundler cannot easily remove unused code coming from zod.
To solve this, Zod introduced a new "flavour" of Zod in its v4, Zod Mini (See release announcement
In louis-bompart/ag-ui#4, I did the experiment of updating Zod to 3 & shifting all use from Zod "classic" to Zod Mini.
This resulted in a reduction of ~84kb uncompressed, which I estimate represents a ~22% improvement for the bundle size of a very simple HTTPAgent.
To note, numbers are less impressive in a more realistic scenario where the output is gzipped; we shave only 8kb (which still represents a ~13% improvement for the bundle size)
louis-bompart/ag-ui#4 represents the change I'd propose (I'll open a PR upstream with this diff later today).
Attached are two metafiles generated by esbuild with my MRE, to help visualize the bundle size changes with https://esbuild.github.io/analyze/
zod-mini.json
baseline.json