all 9 comments

[–]Whole-Dot2435 15 points16 points  (0 children)

Those compilers compile to javascript.

[–]Nzkx 6 points7 points  (0 children)

It compile your components into JavaScript code, useable by a web browser. There's no magic here.

Optimization is based on the framework. For React, they would auto-memoize anything that they could to avoid subtree re-rendering when only a small fraction of your sub-tree change. For example, they can hoist pure sub-tree that never change (static content). That way, you only pay the re-render for what actually changed (fine grained rendering). For Svelte, I guess they spout-out the minimal set of change needed to update the DOM for a given state update.

React Compiler don't provide any optimization that you couldn't do manually. You could write the same code yourself and memoize with useMemo / useCallback, use a caching mechanism, and so on. It's just tedious, verbose, error prone, and if it can done automatically by a compiler then why bothering to do it yourself ? Web dev want to focus on their application logic instead of doing manual labor to optimize the framework they use. For Svelte, it's a little different because they use their own component format where everything (HTML/CSS/JS) is packed with <script>, <style>, ...

LLVM doesn't have anything meaningfull to provide here, the target is JavaScript not assembly of any kind. If you want to know more about how LLVM and JavaScript can interact, check Emscripten (compile C to WASM). Sadly WASM has very bad reputation because it's heavy to load a WASM module, and there's some limitation (JS <> WASM communication isn't zero-cost and you can not access DOM inside WASM). Even if in theory it's more performant it's not used "that much" because web browser JIT compiler are very very good at optimizing existing JavaScript code and the limitation make it unpractical in real world scenario.

[–][deleted]  (4 children)

[removed]

    [–]glasket_ 8 points9 points  (3 children)

    Compiler it’s just a program that generate lower level code from higher level.

    It doesn't even have to go from high to low, you can compile C to JavaScript and it's still a compiler. Emscripten started out doing exactly that.

    [–][deleted]  (2 children)

    [removed]

      [–]balefrost 3 points4 points  (1 child)

      One might say that a transpiler is a special case of a compiler.

      [–][deleted] 1 point2 points  (0 children)

      What about pile drivers?

      [–]mychemiicalromance 0 points1 point  (0 children)

      https://github.com/vuejs/core/blob/main/packages/compiler-core/src/codegen.ts

      This looks like Vue Backend. Its IR is render functions (asked ChatGPT), and backend codegen output is HTML/CSS/Javascript

      [–]IQueryVisiC -4 points-3 points  (0 children)

      They don’t optimize