New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Usage of Printexc increases the bundle size quite a bit #39

Open
osener opened this Issue Jan 5, 2019 · 4 comments

Comments

Projects
None yet
2 participants
@osener
Copy link

osener commented Jan 5, 2019

I'm having a great experience with Repromise, but had to give up on it for a project which aims for the smallest bundle size that's easily achievable. I noticed only Repromise depends on CamlinternalFormat in this particular case, and switching back to Js.Promise resulted in a much smaller bundle.

Is this dependency easily avoidable in Repromise when targeting BuckleScript?

I created a Gist with rollup-plugin-analyzer to demonstrate where most of the 41k bundle (minified) comes from: https://gist.github.com/osener/91dd9838200d53c0b3bf824a9394885c

You can try it out by running

$ git clone https://gist.github.com/91dd9838200d53c0b3bf824a9394885c.git repromise_bundle_size_test
$ cd repromise_bundle_size_test
$ npm install
$ npm run build
@aantron

This comment has been minimized.

Copy link
Owner

aantron commented Jan 5, 2019

Yes, it should be possible to avoid. I seem to have assumed that most projects using Repromise will also somehow pull in Printexc, but I guess that's not the case. If you have a chance (and have not done this already), could you check if removing the call to Printexc.to_string here gives the size results you are looking for?

If so, we can try to remove it in multiple ways. Perhaps we can print the exception using console.error by default. In the docs, we can more strongly encourage developers to set an async exception handler that uses some dependency that the developer is explicitly willing to take on.

@osener

This comment has been minimized.

Copy link

osener commented Jan 5, 2019

@aantron indeed, that single line is the offender. It cuts the minified bundle size from 41k down to 2.3k. Next largest one is es6/curry but I don't think it's necessary to eliminate (except for performance reasons).

BuckleScript's author recommends against using printf and others for similar reasons: BuckleScript/bucklescript#482

image

@osener

This comment has been minimized.

Copy link

osener commented Jan 5, 2019

Using Js.Console.error will cause the exception to look something like this in the console unless this is set up (and that will only work in develelopment mode):

[ [ 'Failure', -2, tag: 248 ], 'message' ]

If this is acceptable I can open a PR. I don't know a way to show OCaml data structures in BuckleScript any other way.

@aantron

This comment has been minimized.

Copy link
Owner

aantron commented Jan 5, 2019

I think that's acceptable, and would be happy to merge a PR for it. We should probably prefix it with "exception," or something like that. I also thought it might be a good idea to give instructions on what the developer can do to get a proper message, but I'm not sure if that will be good post-deployment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment