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

refactor(web-components): use adopted style sheets to set theme tokens #31713

Merged
merged 30 commits into from
Jun 27, 2024

Conversation

marchbox
Copy link
Contributor

@marchbox marchbox commented Jun 13, 2024

Previous Behavior

Update theme token custom properties with document.body.style.setProperty(), this slows the page performance between it calls setProperty() on document.body.style for every single token. And it adds lots of code in <body> element’s style attribute.

New Behavior

Updates theme token custom properties with document.adoptedStyleSheets, this only update the token-specific stylesheet once with the CSS text, and it does so without bloating up <body> element’s style attribute.

setTheme() also caches a theme’s CSS as text, so it doesn’t have to generate the CSS text again if a theme has been used previously.

Performance improvement

The average times to run differ when running tensile-perf against the previous and new code locally, but in generally, the new code is about 30% to 50% faster.

@fabricteam
Copy link
Collaborator

fabricteam commented Jun 13, 2024

📊 Bundle size report

✅ No changes found

@marchbox marchbox self-assigned this Jun 18, 2024
@fabricteam
Copy link
Collaborator

fabricteam commented Jun 18, 2024

Perf Analysis (@fluentui/react-components)

Scenario Render type Master Ticks PR Ticks Iterations Status
FluentProviderWithTheme virtual-rerender 29 28 10 Possible regression
All results

Scenario Render type Master Ticks PR Ticks Iterations Status
Avatar mount 618 629 5000
Button mount 298 303 5000
Field mount 1139 1171 5000
FluentProvider mount 712 698 5000
FluentProviderWithTheme mount 82 89 10
FluentProviderWithTheme virtual-rerender 29 28 10 Possible regression
FluentProviderWithTheme virtual-rerender-with-unmount 74 77 10
MakeStyles mount 861 859 50000
Persona mount 1731 1775 5000
SpinButton mount 1363 1346 5000
SwatchPicker mount 1691 1677 5000

@fabricteam
Copy link
Collaborator

fabricteam commented Jun 18, 2024

Perf Analysis (@fluentui/react-northstar)

⚠️ 2 potential perf regressions detected

Potential regressions comparing to master

Scenario Current PR Ticks Baseline Ticks Ratio Regression Analysis
PortalMinimalPerf.default 89 90 0.99:1 analysis
AttachmentMinimalPerf.default 78 84 0.93:1 analysis
Perf tests with no regressions
Scenario Current PR Ticks Baseline Ticks Ratio
ButtonSlotsPerf.default 325 296 1.1:1
TreeWith60ListItems.default 91 83 1.1:1
IconMinimalPerf.default 397 369 1.08:1
TableMinimalPerf.default 245 230 1.07:1
ChatMinimalPerf.default 461 435 1.06:1
ImageMinimalPerf.default 233 219 1.06:1
ListWith60ListItems.default 379 356 1.06:1
RefMinimalPerf.default 113 107 1.06:1
ButtonMinimalPerf.default 96 91 1.05:1
CardMinimalPerf.default 307 292 1.05:1
ChatDuplicateMessagesPerf.default 158 150 1.05:1
FlexMinimalPerf.default 162 154 1.05:1
RadioGroupMinimalPerf.default 256 244 1.05:1
TextMinimalPerf.default 202 193 1.05:1
AvatarMinimalPerf.default 110 106 1.04:1
FormMinimalPerf.default 233 223 1.04:1
HeaderMinimalPerf.default 206 198 1.04:1
TextAreaMinimalPerf.default 290 279 1.04:1
VideoMinimalPerf.default 451 434 1.04:1
AlertMinimalPerf.default 161 157 1.03:1
CarouselMinimalPerf.default 263 256 1.03:1
DialogMinimalPerf.default 451 437 1.03:1
RosterPerf.default 1555 1517 1.03:1
PopupMinimalPerf.default 355 344 1.03:1
SliderMinimalPerf.default 765 741 1.03:1
SplitButtonMinimalPerf.default 2303 2234 1.03:1
AttachmentSlotsPerf.default 656 645 1.02:1
ButtonOverridesMissPerf.default 661 647 1.02:1
DividerMinimalPerf.default 205 201 1.02:1
GridMinimalPerf.default 196 193 1.02:1
LayoutMinimalPerf.default 200 197 1.02:1
ProviderMergeThemesPerf.default 657 647 1.02:1
CustomToolbarPrototype.default 1485 1449 1.02:1
DropdownMinimalPerf.default 1453 1441 1.01:1
HeaderSlotsPerf.default 463 457 1.01:1
MenuButtonMinimalPerf.default 962 948 1.01:1
SkeletonMinimalPerf.default 198 197 1.01:1
TooltipMinimalPerf.default 1288 1274 1.01:1
TreeMinimalPerf.default 479 474 1.01:1
AnimationMinimalPerf.default 299 300 1:1
DatepickerMinimalPerf.default 3647 3652 1:1
DropdownManyItemsPerf.default 392 393 1:1
InputMinimalPerf.default 516 514 1:1
ListMinimalPerf.default 309 310 1:1
ProviderMinimalPerf.default 195 195 1:1
ChatWithPopoverPerf.default 193 195 0.99:1
MenuMinimalPerf.default 497 501 0.99:1
StatusMinimalPerf.default 390 395 0.99:1
ToolbarMinimalPerf.default 536 539 0.99:1
BoxMinimalPerf.default 192 196 0.98:1
ListNestedPerf.default 315 320 0.98:1
LoaderMinimalPerf.default 195 199 0.98:1
ReactionMinimalPerf.default 211 215 0.98:1
SegmentMinimalPerf.default 189 193 0.98:1
TableManyItemsPerf.default 1111 1132 0.98:1
EmbedMinimalPerf.default 1838 1891 0.97:1
ItemLayoutMinimalPerf.default 674 695 0.97:1
ListCommonPerf.default 362 383 0.95:1
CheckboxMinimalPerf.default 1118 1190 0.94:1
LabelMinimalPerf.default 207 223 0.93:1
AccordionMinimalPerf.default 80 89 0.9:1

@fabricteam
Copy link
Collaborator

fabricteam commented Jun 18, 2024

🕵 FluentUIV0 No visual regressions between this PR and main

@fabricteam
Copy link
Collaborator

fabricteam commented Jun 18, 2024

Perf Analysis (@fluentui/react)

No significant results to display.

All results

Scenario Render type Master Ticks PR Ticks Iterations Status
BaseButton mount 628 652 5000
Breadcrumb mount 1678 1692 1000
Checkbox mount 1705 1711 5000
CheckboxBase mount 1497 1492 5000
ChoiceGroup mount 2984 3006 5000
ComboBox mount 709 678 1000
CommandBar mount 6530 6579 1000
ContextualMenu mount 11902 11984 1000
DefaultButton mount 786 786 5000
DetailsRow mount 2207 2195 5000
DetailsRowFast mount 2202 2219 5000
DetailsRowNoStyles mount 2036 2059 5000
Dialog mount 2646 2789 1000
DocumentCardTitle mount 225 231 1000
Dropdown mount 1986 2009 5000
FocusTrapZone mount 1153 1149 5000
FocusZone mount 1082 1077 5000
GroupedList mount 37376 41676 2
GroupedList virtual-rerender 19916 20056 2
GroupedList virtual-rerender-with-unmount 51135 50536 2
GroupedListV2 mount 228 212 2
GroupedListV2 virtual-rerender 204 205 2
GroupedListV2 virtual-rerender-with-unmount 224 230 2
IconButton mount 1114 1122 5000
Label mount 343 338 5000
Layer mount 2735 2758 5000
Link mount 392 392 5000
MenuButton mount 991 980 5000
MessageBar mount 21161 21193 5000
Nav mount 1996 2069 1000
OverflowSet mount 793 804 5000
Panel mount 1825 1798 1000
Persona mount 743 782 1000
Pivot mount 909 916 1000
PrimaryButton mount 921 942 5000
Rating mount 4652 4652 5000
SearchBox mount 908 931 5000
Shimmer mount 1931 1919 5000
Slider mount 1344 1349 5000
SpinButton mount 2947 3015 5000
Spinner mount 387 386 5000
SplitButton mount 1854 1889 5000
Stack mount 442 446 5000
StackWithIntrinsicChildren mount 882 896 5000
StackWithTextChildren mount 2850 2786 5000
SwatchColorPicker mount 6387 6473 5000
TagPicker mount 1575 1462 5000
Text mount 380 390 5000
TextField mount 930 927 5000
ThemeProvider mount 847 879 5000
ThemeProvider virtual-rerender 574 569 5000
ThemeProvider virtual-rerender-with-unmount 1309 1321 5000
Toggle mount 628 626 5000
buttonNative mount 190 192 5000

@marchbox marchbox marked this pull request as ready for review June 21, 2024 19:45
@marchbox marchbox requested review from a team as code owners June 21, 2024 19:45
Copy link
Member

@chrisdholt chrisdholt left a comment

Choose a reason for hiding this comment

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

Looks like we need to run the deduplication script in yarn and commit the lock file - it should be outlined in the build step for it.

@marchbox
Copy link
Contributor Author

Hi @Hotell, all the conversations are resolved. May I get another pass from you? Thanks!

@chrisdholt chrisdholt enabled auto-merge (squash) June 27, 2024 18:47
Copy link
Member

@TristanWatanabe TristanWatanabe left a comment

Choose a reason for hiding this comment

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

Approving build related changes

@chrisdholt
Copy link
Member

/azp run

Copy link

Azure Pipelines successfully started running 4 pipeline(s).

@chrisdholt chrisdholt merged commit 896c9d3 into microsoft:master Jun 27, 2024
21 checks passed
@marchbox marchbox deleted the set-theme-improvements branch June 27, 2024 23:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants