Check out Qwik; Could Elm adapt?

There is a new kind of JS framework called ‘Qwik’ that only downloads and parses code/handlers when needed, speeding up a frontend application immensely:

It actually reminds me of something in Clojure that is also being developed:

Since Elm is functional, something similar could perhaps be done by slicing the app in separate functions that are JIT-loaded.

What are your thoughts?

1 Like

The pure functional nature of Elm could definitely help it do smarter things. However, in the current state, the JS code delivered from the compilation of your Elm code is very rarely the bottleneck of your webpage loading performance issues.

If you follow the compilation and optimization + minification steps of the guide (Minification · An Introduction to Elm) your compiled and zipped Elm code becomes really small. This is thanks to the ability of the Elm compiler to only include used functions in your compiled call where most JS framework can only work at the module frontier, or at least cannot remove as much as the Elm compiler can.

Companies with 100K line codes of Elm can get JS bundles for the elm part of couple hundreds Kb. Considering this huge scaling advantage, there hasn’t been much need for more advanced strategies yet.

7 Likes

I saw this talk and Qwik looks truly excellent. As Matthieu says though, maybe not required for Elm unless you have really huge projects.

Elm doesn’t even try to be the same solving problem space as Qwik. We barely have SSR in Elm.

Qwik is quite complicated under the hood and it is not a pluggable solution. To reimplement something like that in framework of choice we need SSR and partial hydration and then a way to slice code base by behaviour. Elm can’t do this on granular level. Elm architecture requires our favourite tuple of functions and you can’t divide it further (Cue all blog posts that explain to beginners that we don’t do components in Elm).

And to clarify one thing - Qwik is a solution to real problems and Elm compiler is not a different solution. If you’re conscious of performance metrics of your page Elm is still a naive solution. And maybe it is ok, because most of Elm applications are not concerned with performance and their users can deal with longer LCP/TTI times. That let us keep Elm focused.

But let’s not undermine big advancements in this field by frontend community with solutions that can shave off more and more milliseconds from these metrics.

Also there are different performance metrics to consider and are important in different contexts.

The speaker mentions that most of their customers are in the e-commerce sector. I think that really shows on what they prioritised in their design, as e-commerce is notorious for being highly sensitive for initial page load performance. The impulsive shopping behaviour can really be optimised by putting as little opportunity for you to change your mind before actually paying for something.

Is Elm the ideal technology for that use case? I wouldn’t think so. It optimises for different goals. For instance I’ve been mostly using it in complex B2B use cases, where user sessions can be very lengthy and deal with large amounts of data. Here initial load time is not the most crucial of metrics (albeit it still is something we pay attention to), so much as the time individual user interactions take as you move to complete various tasks within the application. Having a Qwik like design is likely to hurt some of these metrics as you are loading code on demand, so you may have to wait for code to load before an action can be processed (although they seem to be able to at least partially mitigate this by preload tags).

The other important metric that Elm optimises for is developer productivity and happiness. The importance of this again depends on business needs.

2 Likes

The closest thing to this that I’m aware of in Elm would be elm-pages. I know the alpha of v3 is available and a beta is being worked towards.

It’s not the same as Qwik, but it does off features like prerendering pages on serverless. It’s probably closer to Remix or Next/Next which are trying to solve similar problems.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.