Post

Y'ALL. Portable HTML Web Components are fucking cracked. It looks like they are **faster** than the fastest Vanilla JS implementation in the JS Framework Benchmark. I literally reran the benchmark 5 times because I didn't believe it, but every single time they came in first place 🤯

7 reposts54 likes

Curious if delegating with the below is quicker, you allocate like 7 less closures and event listeners this.addEventListener('click', this) handleEvent() {}

Any clue what is making this quicker than vanillajs-lite? Conceptually it doesn't make sense to me, but JS performance is quite surprising sometimes

I let my WCs extend a 'BaseWebComponent' class which takes the template string in the constructor. It puts it into the DOM. It also looks for any elements with 'data-name' and creates those as properties on the component. That avoids dom queries or id clashes. But then am I building a framework? 😭

CLARIFICATION: This implementation is not supposed to imply that Portable HWCs *cause* improved perf, but rather that they are a meaningful improvement on how one can architect WCs They're cracked cuz they let you package the power of Vanilla JS in an ergonomic way that other WC archs haven't

@ryansolid.bsky.social already spelled it out. not understanding feels willful. the benchmark is 'using components' in the same way that hollywood movies are 'shot on iphone' — technically true of you squint, but obviously not what is colloquially meant bsky.app/profile/ryan...

Ryan Carniato@ryansolid.bsky.social

Yeah with one WC it isn't testing anything with WC overhead and the implementation is essentially imperative vanilla. It's more or less vanilla-1 in my article. It is really close to Vanilla because it is. It isn't testing component or declarative overhead. So sort of pointless to benchmark.

Ah yes got it. In that case, I'm curious what you think of my response to Ryan? I'm not trying to willfully/maliciously misunderstand, but I do view things a bit differently

Hawk Ticehurst@hawkticehurst.com

Personally, I view this as one of the fundamental traits/perks of HTML Web Components — it’s effectively a valid/idiomatic way of component-izing Vanilla JS. The point is that you can get Vanilla JS perf in a more ergonomic package, which I think is valuable to demo/talk about.

Lol oh I completely agree, web components *are* just vanilla JS In this case, I’m kind of speaking to the cultural conceptions/attitudes that web components are somehow different than “traditional” vanilla JS I’ve seen ppl say web components are “slower than vanilla JS” in the past

Also note I was precise in my wording: “It looks like they are faster than the fastest Vanilla JS _implementation_ …” Not that they are faster than vanilla JS as a general statement

I dunno if this is a great test for web components. It’s just one big component that’s very brittle and imperative. Kinda the problem with all these kinds of benchmarks, no one seems to test realistic code.

Oh yeah I agree, this *is* an unrealistic implementation of web components and likewise a lot of the other implementations of this benchmark are unrealistic/extremely optimized as well But alas this is the benchmark that is most commonly referred to in the web framework world so here we are 🤷‍♂️

Yeah, we can make a single CE wrapper, then everything inside can be vanilla JS basically, which is not really representative of a real world app (lots of nested components, child slotting, events, strung properties, etc, etc. It would be awesome to update the tests for more of these scenarios.