-
Notifications
You must be signed in to change notification settings - Fork 546
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
Why remove time slicing from vue3? #89
Comments
This is not the right place for this kind of questions, but the gist of it is:
|
Also note that this doesn't mean it's dead forever. Rather consider it postponed until we can re-evaluate what good it can actually bring to Vue if we add it in a later version, and at what cost-benefit ratio. |
@LinusBorg But even so, it still makes sense at the source level. |
In web apps, "janky" updates are typically caused by a combination of synchronous heavy CPU time + raw DOM updates. Time slicing is an attempt at keeping the app responsive during the CPU work, but it affects only CPU work - the flush of the DOM updates must still be synchronous to ensure consistency of the final DOM state. So, imagine two types of janky updates:
Now, time slicing, or concurrent mode brings along another problem: because the framework now schedules and coordinates all the updates, it creates a ton of extra complexity regarding priority, invalidation, re-entry etc. All the logic handling these can never be tree-shaken and this causes the runtime baseline size to bloat up. Even with Suspense and all tree-shakable features included, Vue 3's runtime is still only 1/4 the size of current React + React DOM. Note this isn't saying concurrent mode as a whole is a bad idea. It does provide interesting new ways of dealing with a certain category of problems (in particular related to coordinating async state transitions), but time-slicing (as a sub feature of concurrent) specifically addresses a problem that is much more prominent in React than in other frameworks, at the same time creating its own costs. The trade-offs simply don't seem worthwhile for Vue 3. |
@yyx990803 Thanks for your reply. I think it's also a great summary. It is true that time slicing solves very few problems. Perhaps only a few scenes, such as animation and visualization. 99% scenes are not needed, and it will slow down the total time. There are many problems in React. In addition to what you said, in fact, the use of fiber linked list traversal also limits the diff algorithm and loses many optimization ways. In conclusion, Vue's tradeoff is persuasive. 👍 |
But there are different kinds of interaction. Clicking a button is very different from typing text or using tab navigation. And for the latter 100ms would feel like stutter. I doubt it's appropriate to measure all interactions the same. |
In fact, in addition to animation, other interactions can keep browser responsive through throttle and debounce. In the past few months, I have been engaged in the research of React fiber. So far, I have not found convincing use cases. |
@CyberAP of course. But
|
I've had an issue in Vue 2 with updating on text input on a simple (and I assume a common) task, where you have a nested list that is filtered by the query you enter. In my case the filtering was working very fast, but the huge amount of VNode creation, patch (recursive item list, item also has multiple components in it) and DOM operations made it very slow to react quick enough on input, so of course I had to debounce it. The sluggishness hasn't gone anywhere though, it was just disguised by updating list at a slower pace. I am not exactly sure that time slicing would help here, but it's absolutely a real case where your business logic is fast, but the framework runtime code is slow and you have to deal with it. This is going to vastly improve with Vue 3, but maybe having some extra tools to improve UX would be even better (not necessary time slicing though). |
Just looking for a quick clarification. Are time slicing and concurrent mode the same thing? |
Can be considered one thing, but whether it is called time slicing or concurrent, it refers to the scheduler, which queue the task priority. |
Just wanted to chime in here to say that we (the Preact team) feel the same way about time-slicing and concurrent rendering. Both concepts are extremely complex to implement with only a very tiny fraction of apps benefiting from that. There are many ways we can speed up rendering instead. More AOT is a big area VDOM libraries can tap into, and so are lots of other optimizations. In scenarios where that can't be done, it's usually because of side-effects (network requests, synchronous compilation, etc) like Evan mentioned. In those cases time-slicing won't really help and we believe that other solutions like a simple debounce are more appropriate. Disclaimer: I work on Preact. |
@yyx990803 It needs to be clarified that time slicing of Vue is to split components. If the block logic inside a component exceeds 16ms, it will broken. Such as: render (props) {
while (performance.now() - start < 16) { // broken
}
return h('li', props.msg)
} In react, the unit of slicing is the fiber node, so the block in the components will not block the UI rendering. @marvinhagemeister Preact is different. Its diff and patch are carried out at the same time. |
@132yse I know that, I wrote a good portion of that code in Preact 😉 Nonetheless we had a lot of discussions on our team as to what our future direction should be. Time slicing and concurrent rendering came up a few times and we could implement that given a change in our architecture, but we're not convinced that it's worthwhile for the same reasons Evan shared in detail here. |
No matter how fast you are, when a large page is rendering, any animations are slow down. Progressive and/or virtualized rendering can solve this problem independent of page size. |
no intention to start a debate here but I landed in this issue out of curiosity to know Vue's perspective on concurrent mode. I'm still learning React concurrent mode, but I have to say Concurrent Mode is more than just "being fast" or not, being able to prioritize work is just the foundation for all kinds of innovations. The ability to keep something responsive is just part of it. Speaking of throttle/debounce, as mentioned in the React homepage https://reactjs.org/docs/concurrent-mode-patterns.html, it cannot beat concurrent mode because we cannot set the perfect delay for devices of different performance. Well I agree that it might not be needed for most of the web apps today, and the new features like transition could be implemented somehow in other ways, but I feel the attitude from the issues here is "OK, it is cool but we don't need it", this personally sounds a bit frustrating as a developer, since if we can make something even better, I guess we should give it a try, maybe we can achieve something different but also awesome. Again, no intention to start a debate, just share some of my thoughts. |
@JSerZANP The best way to demonstrate why scheduling/concurrent mode isn't a silver bullet, I suggest that you read through this twitter thread back in 2019, where one React enthusiast attempted to talk smack about other frameworks, boasting React scheduler's superiority. He got proven wrong, quite embarrassingly, by Svelte running in dev mode. And, to rub salt into the wound, his source code was picked apart to expose the fact that his underperforming demo was already cheating by bypassing React to update the 3D scene as well as its fps counter, because if he let React update all the props, the demo would become unresponsive. If I recall correctly, back then someone also whipped up a Vue version, which performed better than its React counterpart as well. So, it's no wonder that the original tweet was later deleted to hide such an embarrassment. To quote Rich Harris' tweet, which rightfully serves as the key takeaway of the thread:
And if you still feel that Vue might be a bit "too slow" to your liking, you can always consult krausest's JS framework benchmark, to see where things stand for yourself. And, hopefully, you will finally realize that there's nothing for Vue users to be frustrated about. |
Well, how to say, there's nothing to get upset about.. Online results
And yes, the best way to get better performance: do work lazy, and clean up after yourself. |
@nin-jin Virtualizing is sure a great way to get better performance on big lists. |
So it's not about lists at all, but about an arbitrary layout. Virtualization is hidden from the application developer. |
The topic of this thread is about time-slicing though 🐈 |
@nin-jin The purpose of this very thread has been about scheduler/concurrent mode that has been inspired by React. Unless $mol employs the exact same concurrent mode as React does, I don't really see how the thing I said has anything to do with what you presented. From my perspective, you can have virtualization without a need to have scheduler/concurrent mode in the framework. And rejecting time slicing feature from Vue doesn't prevent it from benefiting from virtualization. |
We had an implementation of time slicing at all levels, but we removed it because it improves responsiveness at the cost of slowing down visible work. And not always, because on a really large page, recalculation of layout, styles and rendering takes a lot of time and cannot be time sliced. In addition, it introduces non-determinism into the operation of the application, which sometimes gives difficult debugging problems. When we implemented virtualization, it turned out that rendering the visible part of the application usually takes time comparable to one step of time slicing, which made its use completely meaningless. |
Some thoughts:
|
@nin-jin Coming back to the topic at-hand, I think it's great that your first-hand experience in developing $mol aligns with what other framework creators (Svelte, Preact, Vue) have been saying all along: that time slicing feature is not a silver bullet with zero flaws, and it actually is something that many frameworks consciously choose to do without. So in this thread, we now have people from 4 different frameworks coming to the same conclusion after thorough investigations of their own. And, to me, that carries quite a bit of weight. |
I saw that the
time slicing
has been deleted in vue-next here, and no reason was found anywhere.Can I find the answer here? Is it because time slicing is no longer needed or something else?
The text was updated successfully, but these errors were encountered: