ICU4X in a JS polyfill? #979
Replies: 2 comments 1 reply
-
Thanks for your post! It's a goal of ICU4X to support the time zone and calendar logic required to implement Temporal. It is also a goal of ICU4X to be a viable choice for running in a web app; this means building a WebAssembly binary optimized for size. It's hard for me to say right now whether or not the WebAssembly code and data for time zone and calendar logic will fit in a "20K-30K compressed download". Both time zone and calendar logic are in progress and not yet fully implemented; see #533 (time zones) and #534 (calendars). What I can say is that we (myself in particular) are working very hard to get the code and data size down as much as possible. I understand that this is the # 1 blocker for adoption, and we are treating it as such in the design of the code base. Some examples of work we have already done in this area are a wasm size benchmarking tool with a dashboard, which is code size only without data or FFI, and a full-stack example with FFI, currently built on x86-64. Question for you: what subset of functionality from the following list does the polyfill actually need from ICU4X?
Items 1-4 are in scope and scheduled; item 5 is in scope and will get scheduled once Intl.DurationFormat stabilizes; and item 6 is something we may need to consider given that we hope to use ICU4X to implement Temporal in Firefox. No matter which subset of features you need, ICU4X will be sliceable ("tree-shakeable") to just that subset of functionality. |
Beta Was this translation helpful? Give feedback.
-
Would ICU4X ever be appropriate for a JS polyfill? I'm mostly wondering about bundle size. Any idea how many gzip-compressed KB to expect? And what options would maintainers (or developers who want to fork the code) have to control size? I'm mostly thinking about limiting the volume of calendar and/or TZ data included. But also tree-shaking of ICU4X code that's not used on the JS side.
I just did a minified build of @js-temporal/polyfill and it came up as 43K compressed. Adding another 10-20K for better perf and maintainability might be worth it, but past that it's hard to see it being worth it for a client-side-friendly polyfill, esp. in a world (hopefully <18 months away) where evergreen browsers have native Temporal and may not need a polyfill at all.
I suspect that I already know the answer ("no!") but would a 20K-30K compressed download of ICU4X (including minimal locale data and TZ data) ever be realistic?
Assuming the answer is no, I could imagine someone (aka not me!) building a server-only polyfill to support downlevel Node implementations where paying 300KB might be fine in return for orders-of-magnitude speed gains. But that seems hypothetical at this point-- not sure that use case would be worth ICU4X investing in without a real customer and use case.
For context for folks who don't know me, I'm one of the maintainers of @js-temporal/polyfill, which is an intended-for-production-use polyfill that's under development. Other polyfills will certainly be built, and all will likely have similar needs. One of the reasons I'm filing this issue is that other polyfill maintainers are probably wondering the same thing, so centralizing the discussion here may be useful.
Beta Was this translation helpful? Give feedback.
All reactions