Live data from Hacker News

Virtual DOM is pure overhead (2018)

svelte.dev

181–190 of 344 posts

Re: Virtual DOM is pure overhead (2018)

#181
post #60

I have always said: Angular is diffing the model React is diffing the view That’s all. Better to just skip the diffing usually, and grab references to elements and update them when certain events happen. It’s really ok!

https://lit-element.polymer-project.org

lit-html essentially grabs references to elements automatically when parsing a template. You get react-like rendering without any diffing! And does not require build tools.

Re: Virtual DOM is pure overhead (2018)

#182

Personally, I find modern template based approaches like lit-html, hyperhtml/lighterhtml better and faster. And also being far, far smaller. Throw in a CSS framework like bulma or tailwind-css and you are good to go at a smaller footprint and better performance.

And lit works without any build tools!

Re: Virtual DOM is pure overhead (2018)

#183

Earlier quoted context omitted.

> Just curious what the use case for not doing compilation is? I'll add another one - the code that comes out is the code that goes in. Remember the days of Coffeescript and minimization before sourcemaps? When most of your work comes from maintaining a codebase being able to effectively debug your code is crucial and hitting an error in production that is only painfully traced back to development will quickly offset…

I think this is the the big reason to prefer plain old JavaScript. Compilation is ok in Java etc. where you can still debug your Java-code. But with many of these JavaScript frameworks I don't think that is possible, is it? I would add that "debugger" is not mostly a tool for finding and fixing bugs. It is tool for code-understanding, giving you a "live view" of your code, for READING your (or someone else's) code in…

>I would add that "debugger" is not mostly a tool for finding and fixing bugs. It is tool for code-understanding, giving you a "live view" of your code, for READING your (or someone else's) code in the order it executes.

Absolutely! I couldn't agree more.

From the discussion about forking sub-processes from the shell:

The compiler/assembler/disassembler/debugger should be built into the shell, just like ITS DDT at the MIT-AI Lab in 1969! ;)

https://en.wikipedia.org/wiki/Incompatible_Timesharing_Syste...

https://dspace.mit.edu/handle/1721.1/6153

https://github.com/PDP-10/its/blob/master/doc/info/ddt.33

https://github.com/PDP-10/its/blob/master/doc/_info_/ddtord....

https://github.com/PDP-10/its/blob/master/doc/debugging.md

Re: Virtual DOM is pure overhead (2018)

#184

Earlier quoted context omitted.

>functional and composable way components can be designed and implemented. Ughh.. that's the point of all modern FE frameworks... You are putting that description on a pedestal as if that is a unique property of React.

React is more like 'Lambda the Ultimate Web Component'. A component is almost a function returns element. Expanding a component is like calling a function and give it the property. So you can have some abstract common behavior in HOC f and g, then you can have HOC `h = compose(f(g))`. A quick comparison with Angular: @Component({template, style}) seems composable if we stretch a lot. But why make template and style i…

We can only hope that Guy Steele swoops in and saves the day by implementing React in hardware!

https://news.ycombinator.com/item?id=8860722

The Great Quux's Lisp Microprocessor is the big one on the left of the second image, and you can see his name "(C) 1978 GUY L STEELE JR" if you zoom in:

http://ai.eecs.umich.edu/people/conway/VLSI/InstGuide/MIT78c...

Design of a LISP-based microprocessor

https://dl.acm.org/citation.cfm?id=359031

Re: Virtual DOM is pure overhead (2018)

#185

I think this article - and many of the comments on this thread are forgetting the context of how DOM manipulation was typically done when the virtual DOM approach was introduced. Here's the gist of how folks would often update an element. You'd subscribe to events on the root element of your component. And if your component is of any complexity at all - first thing you'd probably do is ask jQuery to go find any child…

the DOM was often used to store state. Every once in a while I'm reminded that I'm mostly disconnected from the way "most" people build things. Thanks for this insight. It finally explains why I hear people talking down about "jQuery developers", if that was something that people actually did. But wow. I've been building javascript-heavy web stuff since the mid 90's and it had never occurred to me to do that. You hav…

If you’ve ever written a video game, I think it’s quite obvious as well. Video games have a main loop, take input, compute the next state, and then merely render the state to the screen. There is no point in manipulating the "UI". The data flow is very clear.

Of course, your game can run entirely "in memory" without a render function, which is basically what the game server does.

So I guess, many people have figured it out but didn’t transfer the knowledge from one area to the other.

Thanks for the insight, because I also always wondered what’s considered so new about React, although I have to admit that I still wrote my fair share of jQuery Spaghetti code.

Re: Virtual DOM is pure overhead (2018)

#186

I think this article - and many of the comments on this thread are forgetting the context of how DOM manipulation was typically done when the virtual DOM approach was introduced. Here's the gist of how folks would often update an element. You'd subscribe to events on the root element of your component. And if your component is of any complexity at all - first thing you'd probably do is ask jQuery to go find any child…

This is how I remember things as well. The Virtual DOM was a huge improvement compared to other contemporary frameworks because it consolidated multiple changes into a single DOM operation. For one thing, all the frameworks at the time we’re doing 2 way bindings. Which meant that the smallest change could end up triggering a bunch of computeds and observables, to the point where any change would trigger a bunch of re…

To me it was not only that as I didn't do games or highly interactive UI's where DOM updates would really matter but it freed me from the burden of ad-hoc updating with jquery as everybody was used to. Unless you had some framework or had invented ways to centrally store state chances are your code was all over the place.

I tried 2-way binding in ExtJS and it seemed to work well at first then I started adding more and more binds to the component and at certain point performance just tanked.

And it was after I started with React already so I just didn't bother to investigate, issue actually was some kind of loop being formed and things aborting due to hitting limits. Which I guess means I used it somewhat incorrectly but I never had that issue with react.

Re: Virtual DOM is pure overhead (2018)

#187

Earlier quoted context omitted.

complexity also kept me away from React. The main reason that it got popular is because it's by Facebook and they know how to manipulate people to use certain products over others (that's their entire business). There have always been simpler and cleaner alternatives. If React was not by Facebook, it would not have gotten popular at all except as a 'cool hack/experiment' - Nobody would have seriously tried to incorpo…

Sorry but what complexity are you talking about? React (particularly in the early days) has always had a comparatively small API surface. You have components with a render method, and in that render method you return other components which you can pass data to via "props" - that's basically react in a nutshell. I've noticed React is often conflated with the wider ecosystem it is a part of (Webpack, Redux, Babel) - pe…

Sure you could use react without JSX compilation, State libraries etc. But you'd just end up writing more code to do less. If your app isn't complex enough to merit the use of webpack, redux, babel etc etc. it probably isn't complex enough to even worry about DOM performance.

Re: Virtual DOM is pure overhead (2018)

#188

2 things I'm not seeing in the article or in the comments so far: 1) The virtual DOM is an abstraction that allows rendering to multiple view implementations. The virtual DOM can be rendered to the browser, native phone UI, or to the desktop. 2) The virtual DOM can, and should, be built with immutable objects which enables very quick reference checks during the change detection cycle.

1: there’s no reason at all why VDOM should be the abstraction over the multiple view implementations; there’s no need: it’s all duck typed, so make DOM (or at least the subset of it that Svelte will generate) the abstraction that other things must implement. I believe this is how Svelte Native works.

Furthermore, as a compiler, Svelte is well placed to render to multiple implementations, efficiently—though implementing it is likely to take more effort if you’re dealing with a different-shaped API. This is demonstrated by the fact that Svelte has two compilation targets at present. First, dom, which is designed for client-side DOM operation; and secondly, ssr, server-side rendering, which is based on emitting strings, and never constructs a DOM.

2: even if you can do things that way, you’re still doing more work than is necessary, because you’re calling the whole render method and performing even simple comparisons that just aren’t necessary. VDOMs render methods are allocation-heavy, because they deliberately create new objects all over the place. In the words of the article, which I assert does deal with this, albeit obliquely: virtual DOM is pure overhead.

Re: Virtual DOM is pure overhead (2018)

#189

I think this article - and many of the comments on this thread are forgetting the context of how DOM manipulation was typically done when the virtual DOM approach was introduced. Here's the gist of how folks would often update an element. You'd subscribe to events on the root element of your component. And if your component is of any complexity at all - first thing you'd probably do is ask jQuery to go find any child…

the DOM was often used to store state. Every once in a while I'm reminded that I'm mostly disconnected from the way "most" people build things. Thanks for this insight. It finally explains why I hear people talking down about "jQuery developers", if that was something that people actually did. But wow. I've been building javascript-heavy web stuff since the mid 90's and it had never occurred to me to do that. You hav…

> Thanks for this insight. It finally explains why I hear people talking down about "jQuery developers", if that was something that people actually did.

Yes. It seems that most of the frameworks people are so enthusiastic about are invented just to prevent bad developers from writing their awful code. Which they end up doing anyway.

Anecdote: years ago, when he decided moving to Angular.js, my boss justified it with "following best practices". Then he proceeded to rewrite all the application components as controllers quering the context to decide how to behave, and talking to everything else through global events. Took me weeks to rewrite everything in a sane way. (Years later it was decided everything was too slow, and it was rewritten in good vanilla js, with a huge performance boost).

Re: Virtual DOM is pure overhead (2018)

#190

Earlier quoted context omitted.

> Also, my dude, there's like half a dozen rules when it comes to vue templates. You mean, wildly inconsistent templates: https://news.ycombinator.com/item?id=19199423 and magically bound JS https://news.ycombinator.com/item?id=17471199 (see code and comments at the end)

I am not sure inconsistent is accurate here. Take the following for example: v-on:click="counter += 1" v-on:click="greet" v-on:click="say('what')" Even without knowing vue, all of those examples are very straightforward in what they're doing. Just because the click event can take multiple options doesn't mean that it's inconsistent. And yea, it's more complicated than "everything in the brackets is javascript and you…

> Just because the click event can take multiple options doesn't mean that it's inconsistent.

That's what inconsistency means. It has multiple v-* attributes and each has different rules on what it accepts.

> ugly code that I've seen in some react projects where the programmer puts a tonne of js code into the templates which as I mentioned before I find an anti-pattern.

JSX isn't templates ;)

> It's a framework, it's supposed to magic away the stupid boilerplate code.

I don't mind magicking away the boilerplate code. I do mind when it's once again so inconsistent in how it magics away that code. For example, in my second link multiple nested properties become properties of `this`, and then:

    // `this.isFolder` magically hoisted into `this` from
    //    `object.computed.isFolder`
    //
    // this.open can be set directly. Magic.
    //    Even though `this.open` magically hoisted 
    //    into `this` from `object.data` which is a function that 
    //    returns an object whose keys and values are hoisted 
    //    into `this`
    //
    // this.model.children cannot be set directly. Not magic
And so on.
Post reply on HN