Skip to content
This repository has been archived by the owner on Mar 4, 2020. It is now read-only.

feat(useStyles): add caching when no inline overrides are applied #2309

Merged
merged 39 commits into from
Feb 10, 2020

Conversation

mnajdova
Copy link
Contributor

@mnajdova mnajdova commented Feb 3, 2020

This PR is adding styles caching when the useStyles hook is used and no inline overrides are applied on the component (styles, design and variables props are not used). The caching is containing the following:

  • theme (weak map referenced key)
  • display name
  • slot name
  • props used in the styles
  • rtl mode
  • disable animations mode

We can enable the caching only when the useStyles is used at this moment, because by using it, we are sure that all props sent to the styles function are primitive values, which can be easily cached.

BREAKING CHANGE

The caching for both styles and variables is enabled by default. If you need to opt out of this, you can use the new performance prop on the Provider:

<Provider theme={theme} performance={{ enableStylesCaching: false }}>
  ...
</Provider>

Note that the variables cache was enabled before this PR, so it is not considered as a breaking change. However you can disabled that one if needed:

<Provider 
  theme={theme} 
  performance={{ 
    enableStylesCaching: false,
    enableVariablesCaching: false 
  }}
>
  ...
</Provider>

@mnajdova mnajdova changed the title feat(useStyles): add caching for no inline overrides feat(useStyles): add caching when no inline overrides are applied Feb 3, 2020
@mnajdova mnajdova changed the title feat(useStyles): add caching when no inline overrides are applied [WIP] feat(useStyles): add caching when no inline overrides are applied Feb 3, 2020
@DustyTheBot
Copy link
Collaborator

DustyTheBot commented Feb 3, 2020

Warnings
⚠️ 59 perf regressions detected

Perf comparison

Status Scenario Fluent TPI Fabric TPI Ratio Iterations Ticks
🔧 Avatar.Fluent 0.46 0.36 1.28:1 2000 918
🦄 Button.Fluent 0.1 0.16 0.63:1 1000 101
🔧 Checkbox.Fluent 0.87 0.3 2.9:1 1000 873
🔧 Dialog.Fluent 0.32 0.17 1.88:1 5000 1604
🔧 Dropdown.Fluent 3.31 0.35 9.46:1 1000 3309
🔧 Icon.Fluent 0.12 0.03 4:1 5000 576
🦄 Image.Fluent 0.05 0.08 0.63:1 5000 230
🔧 Slider.Fluent 1.39 0.32 4.34:1 1000 1392
🔧 Text.Fluent 0.05 0.02 2.5:1 5000 251
🦄 Tooltip.Fluent 0.35 16.92 0.02:1 5000 1761

🔧 Needs work     🎯 On target     🦄 Amazing

Potential regressions comparing to master

Scenario Current PR Ticks Baseline Ticks Ratio
Text.Fluent 251 223 1.13:1
BoxMinimalPerf.default 223 200 1.12:1
TreeMinimalPerf.default 888 805 1.1:1
TextMinimalPerf.default 243 225 1.08:1
VideoMinimalPerf.default 653 606 1.08:1
RadioGroupMinimalPerf.default 385 365 1.05:1
AnimationMinimalPerf.default 438 420 1.04:1
FormMinimalPerf.default 701 677 1.04:1
GridMinimalPerf.default 778 748 1.04:1
LayoutMinimalPerf.default 479 462 1.04:1
TableMinimalPerf.default 545 522 1.04:1
DividerMinimalPerf.default 833 811 1.03:1
ItemLayoutMinimalPerf.default 1600 1552 1.03:1
MenuButtonMinimalPerf.default 1433 1389 1.03:1
AttachmentSlotsPerf.default 3121 3045 1.02:1
FlexMinimalPerf.default 329 321 1.02:1
HierarchicalTreeMinimalPerf.default 759 741 1.02:1
TextAreaMinimalPerf.default 2792 2737 1.02:1
ToolbarMinimalPerf.default 684 668 1.02:1
Dialog.Fluent 1604 1580 1.02:1
Dropdown.Fluent 3309 3257 1.02:1
AccordionMinimalPerf.default 182 181 1.01:1
AlertMinimalPerf.default 522 517 1.01:1
DialogMinimalPerf.default 1586 1572 1.01:1
EmbedMinimalPerf.default 5836 5762 1.01:1
ReactionMinimalPerf.default 2340 2327 1.01:1
AttachmentMinimalPerf.default 857 859 1:1
ChatMinimalPerf.default 1607 1607 1:1
HeaderMinimalPerf.default 395 396 1:1
MenuMinimalPerf.default 1779 1784 1:1
SplitButtonMinimalPerf.default 10918 10913 1:1
LoaderMinimalPerf.default 2247 2265 0.99:1
DropdownMinimalPerf.default 3184 3239 0.98:1
ProviderMinimalPerf.default 527 536 0.98:1
HeaderSlotsPerf.default 1209 1248 0.97:1
Tooltip.Fluent 1761 1823 0.97:1
CarouselMinimalPerf.default 1732 1804 0.96:1
InputMinimalPerf.default 862 894 0.96:1
SegmentMinimalPerf.default 1183 1227 0.96:1
DropdownManyItemsPerf.default 400 433 0.92:1
PopupMinimalPerf.default 307 334 0.92:1
Avatar.Fluent 918 1036 0.89:1
PortalMinimalPerf.default 209 239 0.87:1
AvatarMinimalPerf.default 499 580 0.86:1
Slider.Fluent 1392 1790 0.78:1
SliderMinimalPerf.default 1370 1807 0.76:1
ListCommonPerf.default 700 1002 0.7:1
Checkbox.Fluent 873 1295 0.67:1
CheckboxMinimalPerf.default 3499 6202 0.56:1
LabelMinimalPerf.default 783 1548 0.51:1
Icon.Fluent 576 1123 0.51:1
ImageMinimalPerf.default 217 450 0.48:1
Image.Fluent 230 482 0.48:1
ListMinimalPerf.default 280 591 0.47:1
ButtonSlotsPerf.default 561 1608 0.35:1
IconMinimalPerf.default 268 959 0.28:1
StatusMinimalPerf.default 218 786 0.28:1
ButtonMinimalPerf.default 107 1166 0.09:1
Button.Fluent 101 1219 0.08:1
Perf tests with no regressions
Scenario Current PR Ticks Baseline Ticks Ratio
ChatDuplicateMessagesPerf.default 569 522 1.09:1
RefMinimalPerf.default 145 139 1.04:1
ChatWithPopoverPerf.default 549 534 1.03:1
CustomToolbarPrototype.default 3556 3477 1.02:1
TooltipMinimalPerf.default 2028 2010 1.01:1
ProviderMergeThemesPerf.default 1016 1038 0.98:1

Generated by 🚫 dangerJS

@mnajdova mnajdova changed the title [WIP] feat(useStyles): add caching when no inline overrides are applied feat(useStyles): add caching when no inline overrides are applied Feb 4, 2020
# Conflicts:
#	packages/react/src/components/Provider/Provider.tsx
#	packages/react/src/utils/mergeProviderContexts.ts
-removed obsolete const
@mnajdova mnajdova merged commit 859b8aa into master Feb 10, 2020
@mnajdova mnajdova deleted the feat/add-style-caching branch February 10, 2020 18:25
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants