Skip to content
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

Consider using the Closure Library for CLJS #33

Closed
thheller opened this issue May 22, 2019 · 4 comments

Comments

Projects
None yet
2 participants
@thheller
Copy link

commented May 22, 2019

js-joda is quite a gigantic library and just by including it you are adding almost 500KB of JS to your build. The Closure Library itself actually contains a whole bunch of utilities for working Data/Time data and unlike js-joda it is fully DCE compatible. You can find the code in the goog.i18n.* namespaces

I uploaded a sample build report generated by shadow-cljs to show how huge the added code is. Something also includes cljs.pprint which should be removed. The report was generated for this project which itself contains barely any code.

Apologies if this was considered before and rejected but code size is important for Browser builds and this is entirely too big (IMHO).

@henryw374

This comment has been minimized.

Copy link
Collaborator

commented May 23, 2019

Hi,

Thanks for the report, there are a few points I can make on this:

Firstly the 500k is js-joda and two addon packages. js-joda alone is 200k - and that will likely suffice for some users. More info here: http://juxt.pro/tick/docs/index.html#_timezones

WRT 'too big', too big for whom? I guess you're saying any site where load time is important and/or bandwidth is limited. I'm not developing such size-critical pages myself but I would be surprised if people were using clojurescript on landing pages etc because that itself is at least 200k. I guess you have a certain size budget in mind for each kind of page you're developing and for some people this will blow the budget and won't fit their needs. I'm aware of date-fns for the 'I need more than the platform date lib, but can't afford much more' thing, ie https://github.com/you-dont-need/You-Dont-Need-Momentjs

but let's assume cljs is in budget but an extra 200k isn't. Firstly it looks like js-joda is amenable to shaking, see js-joda/js-joda#214. not sure how you'd do that from cljs ... build with webpack possibly I'm not sure.

In my talk at Clojure/North I talk about new platform dates: https://github.com/tc39/proposal-temporal and size was partly what I had in mind there. I'll have more of a look at goog.i18n but I don't think I'll be trying to get it onto that as js-joda is within budget for the things I'm building and I value being able to drop to java.time api from tick if I need to.

Actually as far as the addon libs go, I think those could be made smaller. e.g. the timezone addon adds zone info for all zone going back way into the past, but maybe you only need zone info about some zones, or for recent history etc. For locales/formatting, if the addons are too big, the js-joda team suggest using the native Intl api https://js-joda.github.io/js-joda/manual/formatting.html

Quite a long answer! I guess more of this needs documenting and if there are many potential users put off by size that's interesting to hear about - and even more so if they're motivated to put in effort into developing solutions to get it within their size budgets.

@henryw374

This comment has been minimized.

Copy link
Collaborator

commented May 23, 2019

I should add, for casual readers, the sizes we are talking are pre-compression. js-joda is 46k when minified and compressed.

@henryw374

This comment has been minimized.

Copy link
Collaborator

commented May 23, 2019

and thanks for pointing out the stray clojure.pprint require :) - now removed.

@thheller

This comment has been minimized.

Copy link
Author

commented May 23, 2019

I only meant to make you aware of some of the utils in the Closure Library which would definitely cover some of the libs use-cases at a fraction of the code cost.

Code size is still important in pretty much all environments. Download size may be less important in non browser envs but you still care about your app starting fast and consuming less memory.

I had not watched your talk before but now I have and it is clear that you did consider using the Closue Library and chose not to use it.

@thheller thheller closed this May 23, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.