-
-
Notifications
You must be signed in to change notification settings - Fork 926
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New approach for mithril rendering? #2307
Comments
Hi @ChrisGitIt ... There's certainly a lot of new exploration going on now that the vdom dust has settled. @isiahmeadows is also working on a new approach, so I'm sure he has a lot of interesting things to say. My own preference is for mithrils hyperscript and lifecycle methods, so if it's a vdom or some other implementation below, I actually don't care much. I haven't bumped into any perf. issues I wasn't able to solve with mithril easily so I haven't been that drawn by other approaches that have popped up lately. Your work on a hydration solution sounds very interesting, so if you'd be willing to share that I think a lot of people would be interested! Don't hesitate to come by the chat on gitter as well! |
to do Memoized DOM in any meaningful way, you really have to pre-compile templates, which usually means writing templates that are no longer "just javascript", but a custom DSL*. the two paradigms are fundamentally incompatible. if you look at imba, it has its own template language. perhaps something like Vue or the original AngularJS could have mutated into something like this, but i dont think this can be shoehorned into any js-centric vdom framework. i think there's room for implementing a detached dom node cache, given that you can solve one of the two most difficult problems in computer science: cache invalidation :) [1] * i guess with sufficiently complex static analysis, like Closure Compiler level of complexity, perhaps it's possible to transform some part of a JavaScript AST into static templates you'd have to detect loop invariants, context/closures, string-key object accesses, etc. and give the compiler knowledge of vdom-style /$0.02 |
Hi @porsager, and thanks for your feedback! I'm also very satisfied with the current mithril way and smile about other frameworks that are "opinionated" and mostly have a high learning curves. About my hydration function:
Within the mithril "render", there is only one line added that checks if there is currently a vdom created or not. The main problem i'm currently facing is when the rendered DOM is different than the mithril DOM. This only happens when the server side rendered dom is saved and served statically (also via CDN). |
Wow.. That's a fast loading and good looking page @ChrisGitIt 👍 I'd love to try out your approach with |
Hi @porsager, thanks for the compliments. The design is not my work. "Only" everything else ;-) I just noticed that the js on the website is minfied. On test.firstmallorca.com you can see the unminified source code. About using a JS-CSS approach: Currently working on a approach that works with SSR (server side rendering) AND that spills out the "above the fold" automatically. I'm thinking about something where there is a special command that you place within your mithrils "main view" to accumulate the css until this point. Would look like this
|
Hi @ChrisGitIt , I'm definetely interested in your hydration script! |
Fun fact: web components are slow, often slower than normal DOM elements. Native ≠ fast, and in this case, it's in part thanks to quite a bit of misplaced object-oriented indirection in the form of the shadow DOM itself. (Compare the performance of Vue and Ember with that of Polymer - they're all three similar to use, but they all three have very different performance curves, and Polymer isn't even close to the rest with list updates.) Custom elements and Also, people suck at correctly managing mutation + asynchrony - most developers struggle how to correctly grasp it and rein it in, especially when using imperative languages. (Try writing a fast HTTP/2 implementation - it's harder than you'd think.) Really, the main bottleneck here is list updates.
Virtual DOM is not the only approach anymore, and hasn't been for the last couple years:
There's been a bit of development in that area recently, so you can be forgiven for not catching on. Angular (starting with v4 IIRC) and Vue both use a traditional virtual DOM reconciler internally, so virtual DOM isn't going anywhere for a while, and this includes Mithril. |
@isiahmeadows One thing I thought of that could be very useful, is taking the incremental-dom approach (where you patch the DOM in-place after an initial render) but doing all the pre-work in simple document fragments You could do a diff against A single document fragment (or many, doens't matter) before truly rendering out to the dom. This would give a couple of things (I been thinking about this alot since I got back from an extended leave) This would still maintain the strengths (and largely leave the vdom implementation as is, with some optimizations)
I don't know if you have considered this. I would be very interested in putting together a demo if you want to explore this concept further. I don't know if I articulated this very well (i'm a little squeezed for time at the time of this writing ha!) Maybe this idea has some legs for making improvements? I'm just happy to hear ideas! I'm also happy to see mithril is seeing alot of new activity again, and I'm willing to help when/if able! |
document fragments are emptied once they're inserted into the live dom, so there's nothing left in them to diff against. |
Oh fair enough (having not investigated it closely as I thought, didn't now that). Is it possible that it might be worthwhile to explore window.localStorage to cheaply save and compare? or am I just getting out of the realm of what we might want to do with that? Though, I think rendering against a docfragment and keeping the state elsewhere would serve still be a worthwhile endeavor considering the other factors. |
@ProtonScott If you read the source, we already use fragments for quite a few things, including rendering Mithril fragments. |
@isiahmeadows I see, maybe the aptly named $doc threw me off in my search (or maybe its been too long since I looked at the source code). So what do you think the way to spearhead is the way to go to improve rendering/performance? |
@ProtonScott To address the other points:
We already do this a lot.
We're missing browser APIs for that. That's the real bottleneck in the DOM currently. Browsers already currently render off-thread as much as possible, so async paints aren't an issue. It's been discussed before, since we aren't the only ones who need it (it's something most frameworks could use): Sadly, nothing meaningful has arisen out of it yet.
Custom events would be slower. Currently, hooks are literally just simple function calls, and custom events would require a lot more ceremony to fire and listen to.
Just trust me in that it's easier said than done. 😉 It'd also take a lot of code.
|
@isiahmeadows Welp, turns out I'm a complete noob at this, aren't I ? 🙁 😆 I appreciate the detailed response, very much so. I will just put the hat in the bag for now. |
Closing this in favor of #1838. |
Hi everybody,
i wonder what the mithril community is saying about the "new tech" that is currently coming up.
Me, personally, try to wrap my head around the
1: shadow dom/ web component
Because it seems it becomes natively available within the current major browsers and might take a lot of rendering performance done by nativ browser specs.
2: Memoized DOM
Here is a recent article: https://medium.freecodecamp.org/the-virtual-dom-is-slow-meet-the-memoized-dom-bb19f546cc52
Are there any other new approaches that are discussed within the mithril community? Is the current VDOM approach still "state of the art"?
I'm surely very satisfied with mithril and its overall approach, but i wonder if other approaches seem to be more future proof ...
Feedback appreciated!
Greets, Chris
Bye the way: I have made mithril hydration script that takes server side rendered dom (https://github.com/MithrilJS/mithril-node-render/) and hydrates it to be used for mithril. Thats mainly to avoid the FOUC when m.route / m.render initiates the app. Anyone interested? Its currently working buttery smooth on a bigger project.
The text was updated successfully, but these errors were encountered: