Skip to content
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

Extract setState queuing into a service, re-use it in EuiIcon #2565

Merged
merged 2 commits into from
Nov 26, 2019

Conversation

chandlerprall
Copy link
Contributor

@chandlerprall chandlerprall commented Nov 26, 2019

Summary

For performance reasons, EuiDataGrid utilizes react-dom::unstable_batchedUpdates to ensure setState calls are batched. EuiIcon suffers from not doing the same thing, which this PR resolves.

Shown in the screen shots below, the current performance is a 1.6s second UI-blocking back-to-back sequence of icon updates. The batched performance shows multiple frame renders and one consolidated React update operation.

I also added an onIconLoad prop to simplify the testing experience, as icon tests must now wait for the queued setState to finish in addition to the dynamic import resolving.

Current EuiIcon performance (icon docs page)

current performance

With batching

updated performance

Checklist

- [ ] Checked in dark mode
- [ ] Checked in mobile
- [ ] Checked in IE11 and Firefox

  • Props have proper autodocs
    - [ ] Added documentation examples
  • Added or updated jest tests
  • Checked for breaking changes and labeled appropriately
    - [ ] Checked for accessibility including keyboard-only and screenreader modes
  • A changelog entry exists and is marked appropriately

@@ -114,18 +114,13 @@ exports[`EuiContextMenu props panels and initialPanelId allows you to click the
class="euiContextMenu__itemLayout"
>
<svg
class="euiIcon euiIcon--medium euiIcon-isLoaded euiContextMenu__icon"
class="euiIcon euiIcon--medium euiIcon-isLoading euiContextMenu__icon"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the 2 affected context menu tests/snapshots don't care what the icon state is so I updated the snapshot instead of "fixing" the test.

Copy link
Contributor

@thompsongl thompsongl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the React dev tools profiler, the number of commits (React applying DOM changes) to render the EuiIcon docs page went from 428 to 3 😮

Spot-checked in Kibana, as well. LGTM

@chandlerprall chandlerprall merged commit cfd81c6 into elastic:master Nov 26, 2019
@chandlerprall chandlerprall deleted the bug/icon-state-thrashing branch November 26, 2019 22:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants