Skip to content

Commit becc2bc

Browse files
committed
perf(material/core): speed up M3 compilation
Mitigates a compile time regression when generating M3 themes. These changes reduce the compilation time in half by caching the dummy theme instead of recreating it for each invocation. We can get away with this since the dummy theme is constant. Although these changes are a significant improvement, there's more room for improvement. Timings for reference: At head: ``` M2 benchmark - 35s M3 benchmark - 90s Theme from #28971 - 19s ``` After these changes changes: ``` M2 benchmark - 36s M3 benchmark - 56s Theme from #28971 - 10s ``` Relates to #28971.
1 parent 4d8af88 commit becc2bc

File tree

1 file changed

+24
-14
lines changed

1 file changed

+24
-14
lines changed

src/material/core/tokens/_m3-tokens.scss

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,29 @@
5757
);
5858
}
5959

60+
$_cached-token-slots: null;
61+
62+
@function _get-token-slots() {
63+
@if ($_cached-token-slots) {
64+
@return $_cached-token-slots;
65+
}
66+
67+
// TODO(mmalerba): Refactor this to not depend on the legacy theme when moving out of
68+
// material-experimental. This is a hack for now because there is no good way to get the token
69+
// slots in material-experimental without exposing them all from material.
70+
$fake-theme: m2-theming.define-light-theme((
71+
color: (
72+
primary: m2-theming.define-palette(m2-theming.$red-palette),
73+
accent: m2-theming.define-palette(m2-theming.$red-palette),
74+
warn: m2-theming.define-palette(m2-theming.$red-palette),
75+
),
76+
typography: m2-theming.define-typography-config(),
77+
density: 0
78+
));
79+
$_cached-token-slots: m2-tokens.m2-tokens-from-theme($fake-theme) !global;
80+
@return $_cached-token-slots;
81+
}
82+
6083
/// Generates a set of namespaced tokens for all components.
6184
/// @param {Map} $systems The MDC system tokens
6285
/// @param {Boolean} $include-non-systemized Whether to include non-systemized tokens
@@ -75,20 +98,7 @@
7598
// DO NOT REMOVE
7699
// This function is used internally.
77100
$systems: format-tokens.private-format-tokens($systems);
78-
79-
// TODO(mmalerba): Refactor this to not depend on the legacy theme when moving out of
80-
// material-experimental. This is a hack for now because there is no good way to get the token
81-
// slots in material-experimental without exposing them all from material.
82-
$fake-theme: m2-theming.define-light-theme((
83-
color: (
84-
primary: m2-theming.define-palette(m2-theming.$red-palette),
85-
accent: m2-theming.define-palette(m2-theming.$red-palette),
86-
warn: m2-theming.define-palette(m2-theming.$red-palette),
87-
),
88-
typography: m2-theming.define-typography-config(),
89-
density: 0
90-
));
91-
$token-slots: m2-tokens.m2-tokens-from-theme($fake-theme);
101+
$token-slots: _get-token-slots();
92102

93103
// TODO(mmalerba): Fill in remaining tokens.
94104
$result: sass-utils.deep-merge-all(

0 commit comments

Comments
 (0)