-
Notifications
You must be signed in to change notification settings - Fork 68
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
Performance improvements #49
Comments
@trentgrover-wf I suspect dart:js interoperability layer as the cause, but I am not sure. If you could somehow improve the overall performance, it would be really awesome! |
I'm also trying to use JS based react components inside Dart. @trentgrover-wf: Are you moving custom components or something available at http://react-components.com ? |
@trentgrover-wf Could you quantify the slow down? What operations are slower? Are there benchmarks that the react-dart team runs? |
@johnmccutchan I'm not aware of any routine benchmarks to use for comparison, but I'll share some more detailed observations and sample code later today. Unfortunately most of the analysis that I'm able to do by implementing identical simple React components in JS and Dart, then compare rendering frame rates and JS stack traces. |
@johnmccutchan I created a repo with a README detailing the issues I'm seeing. Most of the performance degradation appears to be in Dart JS interop overhead in the React render cycle. Any ideas? |
@trentgrover-wf Thank you very much for creating the benchmark. Maybe somebody from |
Ok, I took a quick look at the benchmark, specifically Dart-2.dart, and have some initial observations. First, there's some incredibly fine-grained interop going on here - I see dozens of calls into Dart functions from JS per frame, usually leading to corresponding calls from Dart->JS. Crossing in either direction is potentially expensive, because all arguments and return values need to be converted or proxied (this involves setting properties to store the proxies through functions that are currently not optimizable in V8), but calls from JS->Dart are more expensive because Dart closures are wrapped by several functions in order to implement the conversions and get the calling convention correct. This level of interop is never going to be fast, as least until we have wrapper-less interop with something like the Dev Compiler. The best strategy is to limit the number of language crossings, and limit their overhead by using no-arg functions and primitive arguments. A few ways you might be able to limit crossings:
Another potential issue is that the overall style of Finally, this is my first look into React code, but it looks like all state is stored as Maps. Is this correct? In JavaScript there's a blurry performance line between class-like objects and map-like-objects, but in Dart classes are going to be much faster. I also can't tell if there's a lot of converting Maps between languages, but that will be expensive. I might look into splitting this library into two concerns: 1) Consuming React.js components in Dart, trying to minimize the amount of js-interop used during rendering, and 2) Defining Dart-only React-like components, that again try to minimize interop usage by moving more of the rendering pipeline into Dart. I hope this helps. It's been a while since I worked on |
@justinfagnani thank you very much for the analysis! |
@justinfagnani Thank you very much for such a detailed analysis! |
Link to ongoing discussion on dart-misc: |
Just made a PR that switches over to use the new JS interop and makes other optimizations for performance improvements: #88. |
@trentgrover-wf this can be closed when #88 is merged, IMO. |
We're seeing significant general performance degradation when moving JS based react components to Dart based react components. We will do some performance profiling to trace the most likely drain points, but @hleumas do you have any ideas for how to improve performance?
The text was updated successfully, but these errors were encountered: