Repository navigation
[Perf] Memoize EuiProgress, EuiToken and EuiCard styles #10183
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,10 +22,15 @@ import { EuiI18n } from '../i18n'; | |
| import { CommonProps, ExclusiveUnion } from '../common'; | ||
| import { isNil } from '../../services/predicate'; | ||
|
|
||
| import { useEuiTheme, makeHighContrastColor } from '../../services'; | ||
| import { | ||
| useEuiTheme, | ||
| useEuiMemoizedStyles, | ||
| makeHighContrastColor, | ||
| } from '../../services'; | ||
| import { EuiScreenReaderOnly } from '../accessibility'; | ||
| import { | ||
| euiProgressStyles, | ||
| euiProgressNativeStyles, | ||
| euiProgressIndeterminateStyles, | ||
| euiProgressDataStyles, | ||
| euiProgressLabelStyles, | ||
| euiProgressValueTextStyles, | ||
|
|
@@ -120,7 +125,9 @@ export const EuiProgress: FunctionComponent< | |
| ? { color: makeHighContrastColor(color)(euiTheme.euiTheme) } | ||
| : {}; | ||
|
|
||
| const styles = euiProgressStyles(euiTheme, determinate); | ||
| const styles = useEuiMemoizedStyles( | ||
| determinate ? euiProgressNativeStyles : euiProgressIndeterminateStyles | ||
| ); | ||
|
Comment on lines
+128
to
+130
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is not important. the boost comes from expensive makeHighContrastColor and the native/indeterminate blocks |
||
| const cssStyles = [ | ||
| styles.euiProgress, | ||
| determinate && styles.native, | ||
|
|
@@ -130,7 +137,7 @@ export const EuiProgress: FunctionComponent< | |
| isNamedColor ? styles[color as EuiProgressColor] : styles.customColor, | ||
| ]; | ||
|
|
||
| const dataStyles = euiProgressDataStyles(euiTheme); | ||
| const dataStyles = useEuiMemoizedStyles(euiProgressDataStyles); | ||
| const dataCssStyles = [ | ||
| dataStyles.euiProgress__data, | ||
| size === 'l' && dataStyles[size], | ||
|
|
@@ -139,7 +146,7 @@ export const EuiProgress: FunctionComponent< | |
| euiProgressLabelStyles.euiProgress__label, | ||
| labelProps?.css, | ||
| ]; | ||
| const valueTextStyles = euiProgressValueTextStyles(euiTheme); | ||
| const valueTextStyles = useEuiMemoizedStyles(euiProgressValueTextStyles); | ||
| const valueTextCssStyles = [ | ||
| valueTextStyles.euiProgress__valueText, | ||
| isNamedColor | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💭 Non blocking, general thought: We're creating 6 cached style objects that are in large parts identical (only image/icon use
paddingAmount). If we wanted to optimize further we could split shared styles and dynamic styles into separate memoized chunks. It reduces duplicate cached styles but adds a bit more complexity in code.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mgadewoll, I wanted to avoid changing the generated classes and markup to avoid jumping hurdles with the integration branch and a large EUI PR review :D Do you think it is a wrong approach to optimize for that in this case? I so, we can adjut the code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't have to update anything additional in this PR. I just think we might want to ask what the end state of the style memoization should be: Are we fine with duplicated cached styles or do we opt to optimize that as well and is it worth it. That could be a separate update if we want to do it.
Just for transparency: the split wouldn't change any classes afaik, I'm thinking of something like this:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, i see! I guess these would worth it if a component has a lot of variations that are widely used sizes × colors × …