The Problem
Running synchronous code for longer than the duration of an animation frame causes jagged animation.
Even without animations, long running synchronous code can "freeze" the browser. Even for a "short" freeze, this detracts from UX.
Both problems are more pronounced on mobile devices with slower CPUs.
Tracker can be modified to break/resume if it runs for too long, but this doesn't help if a single reactive function breaks the limit all on it's own, e.g. a template materialization function.
Possible Solution
One goal was to see how few changes could be made to Blaze for this to work.
The solution demonstrated here just adds a single extra file to the blaze
package,
(virtual-dom.js),
and one mod to templating
(to override document
there too).
Obviously with deeper work into Blaze we could get even better results.
This really is just a proof-of-concept. Very limited scenarios were tested. Need to consider:
Possible Improvements
So does this make Blaze faster?
No, it makes Blaze slower, but, non-blocking. This means that even if DOM updates take longer to complete, they won't block animations frames or the browser in general, leading to a significantly smoother experience for the user.
Moving things to a web worker could mean your app as a whole runs faster, since multiple threads are utilized. And with additional opttimizations in place, yes things could actually become a lot faster.