-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
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
[system] Remove theme/styling allocations #43372
Merged
Merged
Changes from 13 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
dab6804
perf: remove lots of waste
romgrk bd0610e
perf: more optimizations
romgrk 5b0db71
fix: bug
romgrk 479d91b
lint
romgrk a691b1a
lint
romgrk c0a4188
lint
romgrk 0ebf9e3
lint
romgrk d75e91b
perf: remove more allocations
romgrk 0f81fe2
refactor: import
romgrk f34a771
perf: avoid theme allocations
romgrk 0fdf5d5
fix
romgrk d007f38
Merge branch 'next' into perf-theme-allocations
romgrk d4c3f0e
refactor: rename pure => fromTheme
romgrk 79137a5
lint
romgrk c19dd34
feat: do the thing
romgrk e2f758e
lint
romgrk ee66b56
Update packages/mui-material/src/utils/memoTheme.ts
romgrk 3939cdb
lint
romgrk 95e4802
Merge branch 'perf-theme-allocations' of github.com:romgrk/material-u…
romgrk 8921455
Merge branch 'next' into perf-theme-allocations
romgrk 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 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 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 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 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 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.
Not sure how PigmentCSS works, could this mess up its extraction?
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.
I checked. Pigment CSS could work if the
fromTheme
is an independent function, not a member of thestyled
. Is it possible?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.
Ok, found the
fromTheme
function below. This should work with Pigment CSS: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.
The function doesn't need to be attached but I did it to make it easy for typescript types, but I think maybe TS can handle inferring
theme
's type just by being astyled(...)()
argument.As for the argument, I made it only
(theme) => ...
instead of({ theme }) => ...
because that ensures that the function only needs to memoizetheme
. If the wholeprops
bundle is included, then there's more stuff to memoize and that is more expensive. I've already sketched out what needs to happen for functions that need access toprops
: https://github.com/mui/material-ui/pull/43372/files#diff-8d1ff500648fb816e094c97e276c5ae924a36d6ab51d2f13afb5e3974e00c490R259-R323There 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.
Agree, let's use
fromTheme(({ theme }) => ({ … })
. Can we update the types to only expecttheme
here and how TS errors if people try to access other props (that would be my only worry).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.
I've updated the code to fit in those constraints, and I've settled on
memoTheme
for the name.