Lightpanda migrate DOM implementation to Zig

(lightpanda.io)

196 points | by gearnode 2 days ago ago

13 comments

  • barishnamazov 2 days ago ago

    This reminds me of the Servo project's journey. Always impressed to see another implementation of the WHATWG specs.

    It's interesting to see Zig being chosen here over Rust for a browser engine component. Rust has kind of become the default answer for "safe browser components" (e.g., Servo, Firefox's oxidation), primarily because the borrow checker maps so well to the ownership model of a DOM tree in theory. But in practice, DOM nodes often need shared mutable state (parent pointers, child pointers, event listeners), which forces you into Rc<RefCell<T>> hell in Rust.

    Zig's manual memory management might actually be more ergonomic for a DOM implementation specifically because you can model the graph relationships more directly without fighting the compiler, provided you have a robust strategy for the arena allocation. Excited to learn from Lightpanda's implementation when it's out.

  • kristopolous 2 days ago ago

    I've been using it for months now ever since I saw their presentation at GitHub

    This is a common flow for me

        lightpanda url | markitdown (microsoft) | sd (day50 streamdown) 
    
    I even have it as a shell alias, wv(). It's way better than the crusty old lynx and links on sites that need JS.

    It's solid. Definitely worth a check

  • lewdwig 2 days ago ago

    A language which is not 1.0, and has repeatedly changed its IO implementation in a non-backwards-compatible way is certainly a courageous choice for production code.

  • nicoburns 2 days ago ago

    This table is informative as to exactly what lightpanda is: https://lightpanda.io/blog/posts/what-is-a-true-headless-bro...

    TL;DR: It does the following:

    - Fetch HTML over the network

    - Parse HTML into a DOM tree

    - Fetch and execute JavaScript that manipulates the DOM

    But not the following:

    - Fetch and parse CSS to apply styling rules

    - Calculate layout

    - Fetch images and fonts for display

    - Paint pixels to render the visual result

    - Composite layers for smooth scrolling and animations

    So it's effectively a net+DOM+script-only browser with no style/layout/paint.

    ---

    Definitely fun for me to watch as someone who is making a lightweight browser engine with a different set of trade-offs (net+DOM+style/layout/paint-only with no script)

  • deepriverfish 2 days ago ago

    it's so tiring that every time there's a post about something being implemented in Zig or C or C++, the Rust brigade shows up trying to pick up a fight.

  • everlier 2 days ago ago

    Wow. Lightpanda is absolutely bonkers of a project. I'd pay dearly for such an option a few years back.

  • MrBuddyCasino 2 days ago ago

    Because We're Not Smart Enough for C++ or Rust

    Very refreshing. Most engineers would rather saw their leg off.

  • steeve 2 days ago ago

    This looks incredible, congratulations!

  • portly 2 days ago ago

    Love to see Zig winning!

  • pulkas 2 days ago ago

    zigdom all-diy

  • Copenjin 2 days ago ago

    Any older project similar to this? Headless browser with js support I mean, I want to check various implementations of this idea.

  • tonyhart7 2 days ago ago

    finally, rewrite in zig movement is coming

  • neoden 2 days ago ago

    I hate to say it, but time is quickly running out for Zig(( AI might never pick it up properly and without that it will never go out of its niche