Reduce build size
Closed this issue · 3 comments
On NPM, build size shows 2.48 mb
Figure out why this is & slim it down to under 30kb or less if possible
I've been exploring the build size issue related to the Ragged project, and here's what I've discovered:
The bulk of the build size is due to the openai
package, which includes numerous internal dependencies and substantial code. A detailed examination using the source-map-explorer
tool revealed that components such as core
and streaming
within the openai
package are the primary contributors to the size.
Here's what I found:
- Enabling Minification: By changing the
minify
setting fromfalse
totrue
in theesbuild
configuration within thebuild.mjs
file, we reduced the build size significantly — from about 240kb to approximately 85kb. However, it's important to note that enabling minification can sometimes lead to harder debugging and slightly longer build times due to the compression process. - Heaviest Components: The
core
andstreaming
modules of theopenai
package are the largest contributors to the size. - Potential Solutions: To reduce the build size further, we might need to consider simplifying these components or exploring lighter alternatives to replace them. Additionally, implementing techniques like code splitting and tree shaking could help optimize the build by only including the necessary parts of the code.
Regarding issue #4:
- Custom EventEmitter Test: Testing a custom EventEmitter to replace rxjs resulted in a modest 8kb reduction. Whether to switch depends on weighing this slight size advantage against the familiarity and robustness of rxjs.
Getting the build size down to under 30kb could be challenging without compromising some functionality or finding alternative, lighter libraries.
Great find @CoderDill ! Would you be interested in creating a PR for this?
@CoderDill 's addition reduced the size to 70kb. I've also removed openai
and rxjs
as dependencies in build.mjs.... altogether, the main build size is <8kb now, and npm will report 21kb probably because of the accompanying d.ts
files
Thanks again @CoderDill !