All Projects → bobzhang → zero-cost-rescript

bobzhang / zero-cost-rescript

Licence: other
A demo project showing close to zero cost when adopting ReScript since version 9

Programming Languages

javascript
184084 projects - #8 most used programming language
ReScript
86 projects
HTML
75241 projects

Zero bundle cost for ReScript

This is a repo showing that when adopting ReScript in your projects, it adds close to zero cost to your bundler size unlike many other languages compiled to JS platform.

We have serveral modules: listLength, listForEachU, listForEach, App, AppOptimized.

For each module, module.mjs is the generated js code using Ecmascript module format,

module.bundle.js is the bundled output using a bundler -- it is a self contained script that runs with all dependencies bundled in.

For listLength, and listForEachU the bundled code is tiny (a couple of hundered bytes including comments).

listForEach is slightly larger since it needs curried runtime support, but its output is still tiny.

App.res is a working example using Rescript with React. You can see the bundled output: App.bundle.js by grepping bs-platform, only lines from 5536-5594 -- less than 60 lines of code -- are needed for ReScript runtime.

Even for such 60 lines of code, it can be optmized away using uncurried calling convention in AppOptimized.res. In the AppOptimized.bundle.js, the ReScript app using React is completely ReScript runtime free.

Note the bundler is configured to not rename variables so that we can have a clear look at the impact of using ReScript.

Build

npm run build

Bundle

The bundle demo uses the open source bundler esbuild

node ./bundle.js
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].