question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Reduce library size [Question] [Enhancement]

See original GitHub issue

At first — thank you for this awesome project.

Recently I debug my bundle and recognise that zod is almost the same as react-dom library and it’s 114kb non gziped code. I use latest version of zod 3.1.0.

Used named import of all zod, but also tried something like import { string } from 'zod' with the same result

import { z } from 'zod';

export const linkShema = z.object({
  title: z.string(),
  link: z.string(),
});

Is it possible to remove at least unused parts of code from my bundle, because 100+ kb it’s a lot.

image

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:9
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
colinhackscommented, Jul 4, 2021

Like @scotttrinh said, there’s a lot of circular dependencies where the base class is dependent on its own subclasses. This is necessary to add convenience methods like .and, .or, .array, etc. So Zod is structurally incompatible with treesplitting to some extent.

I added minification to the Rollup config which seems to have decreased the size of index.mjs by 50kb (50% reduction).

2reactions
scotttrinhcommented, Jun 7, 2021

More manageable when gzipped and/or minified:

$ npx -p gzip-size-cli gzip-size index.mjs --include-original
108 kB → 17.5 kB
$ npx -p js-size js-size index.mjs
┌─────────────────┬─────────┐
│ Original (gzip) │ 17.5 kB │
├─────────────────┼─────────┤
│ Minified (gzip) │ 10.3 kB │
├─────────────────┼─────────┤
│ Difference      │ 7.19 kB │
├─────────────────┼─────────┤
│ Percent         │ 58.94%  │
└─────────────────┴─────────┘

looking at the output, I’m not sure what else we could do: it’s pretty much just the output of tsc here. I don’t think it’s common practice for TypeScript libraries to do any minifying or anything, so I think this ends up falling on you as a consumer to minimize the impact of the library on your bundle. As it is, there is little that can be shaken out of zod, I think, since most of the “weight” is in the parser which is the part that does all of the real work. I’m no tree-shaking expert, though, so if anyone else can weigh in (no pun intended), I’d be interested to hear a more experienced take on this!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Reduce library size · Issue #81 · ipfs/go-ds-s3 - GitHub
For comparison the Java S3 client is ~3mb. Is there any way to reduce this by stripping out unused dependencies? Or just in......
Read more >
c++ reduce library size by excluding unnecessary functions ...
You probably should first try to set up your compilation to minimize size. And the answer to your question depends a lot on...
Read more >
how to reduce library size? - Unity Answers
The problem is when i created an empty android project with only camera in it, the apk size is about 14mb. When i...
Read more >
Reduce library size in Final Cut Pro - Apple Community
Reduce library size in Final Cut Pro. I am not even sure if I am using Libraries, Events and Projects correctly but I...
Read more >
Reduce your app size - Android Developers
Reduce resource count and size · Remove unused resources · Minimize resource use from libraries · Native animated image decoding · Support only...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found