Live data from Hacker News

Lightpanda migrate DOM implementation to Zig

lightpanda.io

111–120 of 144 posts

Re: Lightpanda migrate DOM implementation to Zig

#111
post #99

Earlier quoted context omitted.

Innovation doesn't go for the sake of innovation itself. Innovation should serve a purpose. And the purpose of having programming languages is to overcome the limitations of human mind, of our attention span, of our ability to manipulate concepts expressed in abstractions and syntax. We don't know how long we'll need this. I really like Zig, I wish it appeared several years earlier. But rewriting everything in Zig mi…

I agree that programming languages will no longer need to be as accessible to humans. However there is still a strong argument to be made for protections/safety that languages can provide. e.g. would you expect a model (assuming it had the same expertise in each language) to make more mistakes in ASM, C, Zig, or Rust? I imagine most would agree that ASM/C would be likely to have the most mistakes simply because fewer…

> would you expect a model (assuming it had the same expertise in each language) to make more mistakes in ASM, C, Zig, or Rust?

"assuming it had the same expertise in each language" is the most important part here, because the expertise of AI with these languages is very different. And, honestly, I bet on C here because its code base is the largest, the language itself is the easiest to reason about and we have a lot of excellent tooling that helps mitigate where it falls short.

> I imagine most would agree that ASM/C would be likely to have the most mistakes simply because fewer constraints are enforced as you go closer to the metal.

We need these constraints because we can't reliably track all the necessary details. But AI might be much more capable (read — scalable) in that, so all the complexity that we need to accumulate in a programming language it might just know out of the way it's built.

Re: Lightpanda migrate DOM implementation to Zig

#112
post #61

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

In my experience LLMs are really good at following code examples and constraints (tests).

So even if they don't get to train much on some technology, all you need is some guidance docs in AGENTS.md

There's a plus in being fresh too: LLMs aren't going to be heavily trained on outdated tutorials and docs. Like React for example.

Re: Lightpanda migrate DOM implementation to Zig

#113
post #3

Earlier quoted context omitted.

Hi, I am Francis, founder of Lightpanda. We wrote a full article explaining why we choose Zig over Rust or C++, if you are interested: https://lightpanda.io/blog/posts/why-we-built-lightpanda-in-... Our goal is to build a headless browser, rather than a general purpose browser like Servo or Chrome. It's already available if you would like to try it: https://lightpanda.io/docs/open-source/installation

Choosing something like Zig over C++ on simplicity grounds is going to be a false economy. C++ features exist for a reason . The complexity is in the domain. You can't make a project simpler by using a simplistic language: the complexity asserts itself somehow, somewhere, and if a language can't express the concept you want, you'll end up with circumlocution "patterns" instead. Build system complexity disappears when…

C++ features exist for a reason but it may not be a reason that is applicable to their use case. For example, C++ has a lot of features/complexity that are there primarily to support low-level I/O intensive code even though almost no one writes I/O intensive code.

I don't see why C++ would be materially better than Zig for this particular use case.

Re: Lightpanda migrate DOM implementation to Zig

#114
post #76
post #74

Earlier quoted context omitted.

> I don't know if the "reasonable definition" of GC matters at all If you define all non-red colors to be green, it is impossible to talk about color theory. > And Rust wins the Razzie Award for most painful development and lack of similarly powerful arenas. That's a non-quantifiable skill issue. Segfaults per issue is a quantifiable thing. > When you have less safety for any property, you're guarnateed to have more…

> If you define all non-red colors to be green, it is impossible to talk about color theory. Except reference counting is one of the two classical GC algorithms (alongside tracing), so I think it's strange to treat it as "not a GC". But it is true that GC/no-GC distinction is not very meaningful given how different the tradeoffs that different GC algorithms make are. Even within these basic algorithms there are combi…

> Except reference counting is one of the two classical GC algorithms (alongside tracing), so I think it's strange to treat it as "not a GC". But it is true that GC/no-GC distinction is not very meaningful given how different the tradeoffs that different GC algorithms make are.

That's not the issue. Calling anything with opt-in reference counting a GC language. You're just fudging definitions to get to the desired talking point. I mean, C is, by that definition, a GC language. It can be equipped with

> That it's not as easily quantifiable doesn't make it any less real.

It makes it more subjective and easy to bias. Rust has a clear purpose. To put a stop to memory safety errors. What does it's painful to use? Is it like Lisp to Haskell or C to Lisp.

> For example, it would be hard to distinguish between Java and Haskell.

It would be possible to objectively distinguish between Java and Haskell, as long as they aren't feature-by-feature compatible.

If you can make a program that halts on that feature, you can prove you're in language with that feature.

> If what you truly believed is that more compile-time safety always wins, then it is you who should be advocating for ATS over Rust.

Yeah, because you fight a strawman. Having a safe language is a precondition but not enough. I want it to be as performant as C as well.

Second, even if you have the goal of moving to ATS, developing ATS-like isn't going to help. You need a mass of people to move there.

Re: Lightpanda migrate DOM implementation to Zig

#115
post #111

Earlier quoted context omitted.

I agree that programming languages will no longer need to be as accessible to humans. However there is still a strong argument to be made for protections/safety that languages can provide. e.g. would you expect a model (assuming it had the same expertise in each language) to make more mistakes in ASM, C, Zig, or Rust? I imagine most would agree that ASM/C would be likely to have the most mistakes simply because fewer…

> would you expect a model (assuming it had the same expertise in each language) to make more mistakes in ASM, C, Zig, or Rust? "assuming it had the same expertise in each language" is the most important part here, because the expertise of AI with these languages is very different. And, honestly, I bet on C here because its code base is the largest, the language itself is the easiest to reason about and we have a lot…

I’m going to assume you’re open to an honest discussion here.

> "assuming it had the same expertise in each language" is the most important part here, because the expertise of AI with these languages is very different.

You are correct, but I am trying to illustrate that assuming some ideal system with equal expertise, the languages with more safety would win out in productivity/bugs over those with less safety.

As in to say that it could be worth investing further in safer programming languages because AI would benefit.

> We need these constraints because we can't reliably track all the necessary details.

AI cannot reliably track the details either (yet, though I am sure it can be done). Even if it could, it would be a complete waste of resources (tokens).

Why have an AI determine the type of a variable when it could be done in a deterministic manner with a compiler or linter?

To me these arguments closely mirror/follow arguments of static/dynamically typed languages for human programmers. Static type systems eliminate certain kinds of errors and can produce higher quality programs. AI systems will benefit in the same way if not more by getting instant feedback on the validity of their program.

Re: Lightpanda migrate DOM implementation to Zig

#116
post #114
post #76

Earlier quoted context omitted.

> If you define all non-red colors to be green, it is impossible to talk about color theory. Except reference counting is one of the two classical GC algorithms (alongside tracing), so I think it's strange to treat it as "not a GC". But it is true that GC/no-GC distinction is not very meaningful given how different the tradeoffs that different GC algorithms make are. Even within these basic algorithms there are combi…

> Except reference counting is one of the two classical GC algorithms (alongside tracing), so I think it's strange to treat it as "not a GC". But it is true that GC/no-GC distinction is not very meaningful given how different the tradeoffs that different GC algorithms make are. That's not the issue. Calling anything with opt-in reference counting a GC language. You're just fudging definitions to get to the desired ta…

> Calling anything with opt-in reference counting a GC language

Except I never called it "a GC language" (whatever that means). I said, and I quote, "Rust does have a GC". And it does. Saying that it's "opt in" when most Rust programs use it (albeit to a lesser extent than Java or Go programs, provided we don't consider Rust's special case of a single reference to be GC) is misleading.

> Rust has a clear purpose. To put a stop to memory safety errors.

Yes, but 1. other languages do it, too, so clearly "stopping memory errors" isn't enough, 2. Rust does it in a way that requires much more use of unsafe escape hatches than other languages, so it clearly recognises the need for some compromise, and 3. Rust's safety very much comes at a cost.

So its purpose may be clear, but it is also very clear that it makes tradeoffs and compromises, which implies that other tradeoffs and compromises may be reasonable, too.

But anyway, having a very precise goal makes some things quantifiable, but I don't think anyone thinks that's what makes a language better than another. C and JS also have very clear purposes, but does that make them better than, say, Python?

> Having a safe language is a precondition but not enough. I want it to be as performant as C as well... You need a mass of people to move there.

So clearly you have a few prerequisites, not just memory safety, and you recognise the need for some pragmatic compromises. Can you accept that your prerequisites and compromises might not be universal and there may be others that are equally reasonable, all things considered?

I am a proponent of software correctness and formal methods (you can check out my old blog: https://pron.github.io) and I've learnt a lot over my decades in industry about the complexities of software correctness. When I choose a low-level language, to switch away from C++ my prerequisites are: a simple language with no implicitness (I want to see every operation on the page) as I think it makes code reviews more effective (the effectiveness of code reviews has been shown empirically, although not the relationship to language design) and fast compilation to allow me to write more tests and run them more often.

I'm not saying that my requirements are universally superior to yours, and my interests also lie in a high emphasis on correctness (which extends far beyond mere memory safety), it's just that my conclusions and perhaps personal preferences lead me to prefer a different path to your preferred one. I don't think anyone has any objective data to support the claim that my preferred path to correctness is superior to yours or vice-versa.

I can say, however, that in the 1970s, proponents of deductive proofs warned of an impending "software crisis" and believed that proofs are the only way to avoid it (as proofs are "quantifiably" exhaustive). Twenty years later, one of them, Tony Hoare, famously admitted he was wrong, and that less easily quantifiable approaches turned out to be more effective than expected (and more effective than deductive proofs, at least of complicated properties). So the idea that an approach is superior just because it's absolute/"precise" is not generally true.

Of course, we must be careful not to extrapolate and generalise in either direction, but my point is that software correctness is a very complicated subject, and nobody knows what the "best" path is, or even if there is one such best path.

So I certainly expect a Rust program to have fewer memory-safety bugs than a Zig programs (though probably more than a Java program), but that's not what we care about. We want the program to have the fewest dangerous bugs overall. After all, I don't care if my user's credit-card data is stolen due to a UAF or due to SQL injection. Do I expect a Rust program to have fewer serious bugs than a Zig program? No, and maybe the opposite (and maybe the same) due to my preferred prerequisites I listed above. The problem with saying that we should all prefer the more "absolute" approach, though it could possibly harm less easily-quantifiable aspects, because it's at least absolute in whatever it does guarantee is that this belief has already been shown to not be generally true.

(As a side note, I'll add that a tracing GC doesn't necessarily have a negative impact on speed, and may even have a positive one. The main tradeoff is RAM footprint. In fact, the cornerstone of tracing algorithms is that they can reduce the cost of memory management to be arbitrarily low given a large-enough heap. In practice, of course, different algorithms make much more complicated pragmatic tradeoffs. Basic refcounting collectors primarily optimise for footprint.)

Re: Lightpanda migrate DOM implementation to Zig

#117

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 pr…

Too late now, but is the requirement for shared mutable state inherent in the problem space? Or is it just because we still thought OOP was cool when we started on the DOM design?

Yes. It is required for W3C's DOM APIs, which give access to parent nodes and allow all kinds of mutations whenever you want.

Event handlers + closures also create potentially complex situations you can't control, and you'll need a cycle-breaking GC to avoid leaking like IE6 did.

You can make a more restricted tree if you design your own APIs with immutability/ownership/locking, but that won't work for existing JS codebases.

Re: Lightpanda migrate DOM implementation to Zig

#118
post #64
post #8

Earlier quoted context omitted.

When I was working before on something that used headless browser agents, the ability to do a screenshot (or even a recording) was really great for debugging... so I am not sure about the "no paint". But hey everything in life is a trade-off.

Really depends on what you want to do with the agents. Just yesterday I was looking for something like this for our web access MCP server[0]. The only thing that it needs to do is visit a website and get the content (with JS support, as it's expected that most pages today use JS), and then convert that to e.g. Markdown. I'm not too happy with the fact that Chrome is one of our memory-hungriest parts of all the MCP se…

Well, it was "normal" crawlers that needed to work perfectly and deterministically (as best as possible), not probabilistically (AI); speed was no issue. And I wanted to debug when something went wrong. So yeah for me it was crucial to be able to record/screenshot.

So yeah, everything is a trade-off, and we needed a different trade-off; we actually decided to not use headless chromium, because they are slight differences, so we ended up using full chrome (not even chromium, again - slight differences) with xvfb. It was very, very memory hungry; but again was not an issue

(I used "agent" as in "browser agent", not "AI agent", I should be more precise I guess.)

Re: Lightpanda migrate DOM implementation to Zig

#119
post #111

Earlier quoted context omitted.

> would you expect a model (assuming it had the same expertise in each language) to make more mistakes in ASM, C, Zig, or Rust? "assuming it had the same expertise in each language" is the most important part here, because the expertise of AI with these languages is very different. And, honestly, I bet on C here because its code base is the largest, the language itself is the easiest to reason about and we have a lot…

I’m going to assume you’re open to an honest discussion here. > "assuming it had the same expertise in each language" is the most important part here, because the expertise of AI with these languages is very different. You are correct, but I am trying to illustrate that assuming some ideal system with equal expertise, the languages with more safety would win out in productivity/bugs over those with less safety. As in…

Yes, I get your point and I think your arguments are valid, it's just not the whole story.

The thing about programming languages is that both for their creators and advocates a significant part of motivation to drive is emotions and not the rational necessity alone. Learning a new programming language along with its ecosystem is an investment of time and effort, it is something that our brains mark as important and therefore protected (I'm looking at Rust). Now when AI is going to write all the code, that emotional part might eventually dissolve and move to something else, leaving the question of choice of a programming language much less relevant. Like the list of choices Claude Code shows to you in planning mode: "do you wish to use SQLite, PostgreSQL or MySQL as a database for your project?" (*picking the "Recommended" option)

That said, I hope that Zig will make it to version 1.0 before AI turns all the tables and sweeps many things away. It might be my bias and I'm wrong and overestimating the irrational part, then I'll be glad to admit my mistake.

Re: Lightpanda migrate DOM implementation to Zig

#120
post #107
post #85

Earlier quoted context omitted.

You’re changing the argument. The point wasn’t whether more safety is “worth it”, but that comparing ease while ignoring which invariants are enforced is misleading. Zig can feel simpler because it encodes fewer guarantees. I’m not saying one approach is better, only that this comparison shifts the goalposts.

Then we're in agreement. Both languages give you something that may be important, but it has a price.

You're changing the argument again. I'm not in agreement with your statement.
Post reply on HN