Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Kill unnecessary re-renders in ElementWrapper (elastic#31734)
## Summary (fixes elastic#29700) This is a small change that creates a huge impact on UI performance in Canvas. As the mouse moves over a workpad, several parts of the state of the workpad, (the element hovered, the element moved if one is being held, etc) change. These changes in state were causing every active Element to re-render in React. In short, you may hover Element 10, but Elements 1-9 re-render because the state of the entire workpad changes. This would happen even if the mouse were moved a single pixel. By short-circuiting that re-render with a fast comparison, we prevent any Elements that are not affected from re-rendering... freeing up the main thread. This performance impact intensifies as one adds Elements to the workpad. Here is a performance shapshot before this change was made. Notice the React tree reconciliation encompasses the entire 280ms. This reflects a single state change flowing through all of the Elements on the workpad, (each orange "stalactite" descending downwards is an Element): ![screen shot 2019-02-21 at 11 49 48 am](https://user-images.githubusercontent.com/297604/53197762-76960380-35e0-11e9-9069-a30df5fd4b2f.png) Here is a snapshot after. That reconciliation now completes in 50ms or less: ![screen shot 2019-02-21 at 11 49 30 am](https://user-images.githubusercontent.com/297604/53197845-afce7380-35e0-11e9-8991-572462b441eb.png) *This is not the end of this problem.* There are many other opportunities to prevent re-rendering, and we need to focus on killing the need for the comparison in the first place. @monfera and @w33ble will be instrumental in making these changes in the future... for now, though, this gets the job done. ### Checklist Use ~~strikethroughs~~ to remove checklist items you don't feel are applicable to this PR. - [x] This was checked for cross-browser compatibility, [including a check against IE11](https://github.com/elastic/kibana/blob/master/CONTRIBUTING.md#cross-browser-compatibility) - [ ] ~~Any text added follows [EUI's writing guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/master/packages/kbn-i18n/README.md)~~ - [ ] ~~[Documentation](https://github.com/elastic/kibana/blob/master/CONTRIBUTING.md#writing-documentation) was added for features that require explanation or tutorials~~ - [ ] ~~[Unit or functional tests](https://github.com/elastic/kibana/blob/master/CONTRIBUTING.md#cross-browser-compatibility) were updated or added to match the most common scenarios~~ - [ ] ~~This was checked for [keyboard-only and screenreader accessibility](https://developer.mozilla.org/en-US/docs/Learn/Tools_and_testing/Cross_browser_testing/Accessibility#Accessibility_testing_checklist)~~ ### For maintainers - [x] This was checked for breaking API changes and was [labeled appropriately](https://github.com/elastic/kibana/blob/master/CONTRIBUTING.md#release-notes-process) - [ ] ~~This includes a feature addition or change that requires a release note and was [labeled appropriately](https://github.com/elastic/kibana/blob/master/CONTRIBUTING.md#release-notes-process)~~
- Loading branch information