by jlongster · 11y ago · 0 comments
I wonder if there's even value in something like an asm.js-compiled layout system, which absolutely positions elements. One of the insights of React Native is that to build apps, we really only need a small subset of the web's layout algorithms. Only flexbox, really. So if we recognize this subset, and remove everything else, there main thread can focus on really smooth performance.
React Native even performs the flexbox layout on a 3rd thread, and tells the main thread where to absolutely position stuff.
Obviously we want to re-use as much of HTML as we can, but there might be some crazy ways to remove stuff from the main thread.
EDIT: It should be noted that Mercury, a React-inspired library (https://github.com/Raynos/mercury), has examples of running in a web worker. It is pretty cool, but I think it needs to be fleshed out more.
The biggest problems with performance are:
- GC pauses
- triggering reflow
- marshalling data across interfaces (serialization/deserialization of native types into strings and back again).
That last one is an absolute killer when it comes to applying 3D matrix transforms. Basically, you're taking an array of floats, serializing them into a string to do an element.style property assignment, so that the browser can then take that stringified representation and convert it back into an array of floats that it can apply. Huge perf hit here.
People attribute pauses to GC, when it's sometimes just the browser container environment acting up and there's nothing we can do about it - so it's easy to write it off as GC. Not sure about today, but 1.5 years ago (i = new Image(), i.src="http...") could block the JS thread for as much as 19ms. In a larger app, it's easy to write that off as GC, but (at least on iOS) the performance tooling is really lacking and it's tough to find the culprit.
Reflowing is a big deal, I agree.
I'd love to chat more about this with both of you, this seems like a direction definitely worth exploring.
Maybe we could set up a github project for it? Or talk in an issue on your existing repo, nwienert?
Some reading:
https://news.ycombinator.com/item?id=6982485 http://stackoverflow.com/questions/18056922/is-there-a-way-t...
Edit: webpack + webwoker: https://github.com/webpack/webpack/tree/master/examples/web-...
Might be worth reading one of the react native devs about why animations might still be hard: http://jlongster.com/First-Impressions-using-React-Native#co...
This idea is also why I hooked up the css-layout project (https://github.com/facebook/css-layout) to a live demo to play around with: http://layout.jlongster.com/
https://github.com/reactjs/react-future/tree/master/05%20-%2...
EDIT: Searching for "Worker" right now didn't bring any mention, but it seems it is a very recent edit (cf https://github.com/gss/gss.github.io/commit/d6a931e3629d4b5d...).