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

perf: use inline-style-expand-shorthand for expanding#1925

Merged
layershifter merged 10 commits intomasterfrom
chore/use-fela-plugin
Feb 26, 2020
Merged

perf: use inline-style-expand-shorthand for expanding#1925
layershifter merged 10 commits intomasterfrom
chore/use-fela-plugin

Conversation

@layershifter
Copy link
Member

@layershifter layershifter commented Sep 12, 2019

BREAKING CHANGES

As inline-style-expand-shorthand doesn't support expanding of font CSS property this probably should be done manually in styles/overrides:

Before

{
  font: "15px arial, sans-serif",
}

After

{
  fontSize: "15px",
  fontFamily: "arial, sans-serif",
}

This PR replaces css-shorthand-expand (we used compiled version of it) with inline-style-expand-shorthand which is used in fela-plugin-expand-shorthand.

We cannot use fela-plugin-expand-shorthand as it introduced regressions due merging order so I just replaced css-shorthand-expand which allows us to gain 10% performance and drop complied code.

🏁 Measures

yarn perf --filter *ChatWithPop*

Performance diff is 9.71% for the example below.

Before

Example min avg median max
ChatWithPopover.perf.tsx 363.42 378.07 372.95 453.05
ChatWithPopover.perf.tsx 363.07 379.59 375.67 425.95
378.83

After

Example min avg median max
ChatWithPopover.perf.tsx 328.7 341.16 338.68 383.49
ChatWithPopover.perf.tsx 332.13 345.61 341.96 424.88
343.385

@DustyTheBot
Copy link
Collaborator

DustyTheBot commented Sep 12, 2019

Warnings
⚠️ Package (or peer) dependencies changed. Make sure you have approval before merging!
⚠️ 5 perf regressions detected

Changed dependencies are detected.

Changed dependencies in packages/react/package.json

package before after
inline-style-expand-shorthand - ^1.2.0

Perf comparison

Status Scenario Fluent TPI Fabric TPI Ratio Iterations Ticks
🔧 Avatar.Fluent 0.46 0.4 1.15:1 2000 912
🦄 Button.Fluent 0.11 0.18 0.61:1 1000 114
🔧 Checkbox.Fluent 0.77 0.33 2.33:1 1000 771
🔧 Dialog.Fluent 0.3 0.19 1.58:1 5000 1488
🔧 Dropdown.Fluent 3.25 0.41 7.93:1 1000 3251
🔧 Icon.Fluent 0.12 0.03 4:1 5000 604
🦄 Image.Fluent 0.04 0.08 0.5:1 5000 217
🔧 Slider.Fluent 1.18 0.3 3.93:1 1000 1180
🔧 Text.Fluent 0.05 0.02 2.5:1 5000 241
🦄 Tooltip.Fluent 0.1 19.85 0.01:1 5000 485

🔧 Needs work     🎯 On target     🦄 Amazing

Potential regressions comparing to master

Scenario Current PR Ticks Baseline Ticks Ratio
DropdownManyItemsPerf.default 316 343 0.92:1
Checkbox.Fluent 771 871 0.89:1
Dialog.Fluent 1488 1728 0.86:1
MenuMinimalPerf.default 1611 1915 0.84:1
SegmentMinimalPerf.default 813 1211 0.67:1
Perf tests with no regressions
Scenario Current PR Ticks Baseline Ticks Ratio
TextMinimalPerf.default 343 247 1.39:1
AccordionMinimalPerf.default 208 181 1.15:1
ChatWithPopoverPerf.default 593 520 1.14:1
Tooltip.Fluent 485 426 1.14:1
ProviderMinimalPerf.default 648 573 1.13:1
HeaderSlotsPerf.default 1305 1164 1.12:1
ListNestedPerf.default 719 665 1.08:1
ListCommonPerf.default 802 749 1.07:1
Icon.Fluent 604 570 1.06:1
CheckboxMinimalPerf.default 3470 3307 1.05:1
LayoutMinimalPerf.default 541 516 1.05:1
StatusMinimalPerf.default 233 221 1.05:1
ListMinimalPerf.default 333 321 1.04:1
ToolbarMinimalPerf.default 796 782 1.02:1
Image.Fluent 217 213 1.02:1
HierarchicalTreeMinimalPerf.default 741 735 1.01:1
ProviderMergeThemesPerf.default 1126 1111 1.01:1
GridMinimalPerf.default 709 708 1:1
ItemLayoutMinimalPerf.default 1581 1587 1:1
MenuButtonMinimalPerf.default 1485 1490 1:1
RadioGroupMinimalPerf.default 399 401 1:1
AttachmentSlotsPerf.default 3161 3212 0.98:1
ChatMinimalPerf.default 404 414 0.98:1
DropdownMinimalPerf.default 3564 3626 0.98:1
FlexMinimalPerf.default 346 353 0.98:1
ImageMinimalPerf.default 223 227 0.98:1
ListWith60ListItems.default 157 160 0.98:1
Text.Fluent 241 247 0.98:1
ButtonMinimalPerf.default 113 117 0.97:1
LoaderMinimalPerf.default 808 832 0.97:1
TableMinimalPerf.default 531 548 0.97:1
CarouselMinimalPerf.default 1803 1885 0.96:1
SliderMinimalPerf.default 1231 1278 0.96:1
TreeMinimalPerf.default 810 841 0.96:1
ButtonSlotsPerf.default 627 657 0.95:1
IconMinimalPerf.default 289 303 0.95:1
TooltipMinimalPerf.default 630 666 0.95:1
Dropdown.Fluent 3251 3427 0.95:1
LabelMinimalPerf.default 807 855 0.94:1
Avatar.Fluent 912 972 0.94:1
AvatarMinimalPerf.default 470 506 0.93:1
BoxMinimalPerf.default 234 252 0.93:1
HeaderMinimalPerf.default 415 445 0.93:1
TreeWith60ListItems.default 212 227 0.93:1
Slider.Fluent 1180 1281 0.92:1
InputMinimalPerf.default 810 894 0.91:1
PopupMinimalPerf.default 326 357 0.91:1
CustomToolbarPrototype.default 3152 3452 0.91:1
FormMinimalPerf.default 664 734 0.9:1
AttachmentMinimalPerf.default 857 960 0.89:1
EmbedMinimalPerf.default 4943 5567 0.89:1
SplitButtonMinimalPerf.default 9625 10897 0.88:1
PortalMinimalPerf.default 218 252 0.87:1
DividerMinimalPerf.default 905 1051 0.86:1
TextAreaMinimalPerf.default 2405 2811 0.86:1
AnimationMinimalPerf.default 494 582 0.85:1
DialogMinimalPerf.default 1619 1927 0.84:1
VideoMinimalPerf.default 653 778 0.84:1
ChatDuplicateMessagesPerf.default 323 387 0.83:1
ReactionMinimalPerf.default 1889 2287 0.83:1
RefMinimalPerf.default 146 182 0.8:1
AlertMinimalPerf.default 492 633 0.78:1
Button.Fluent 114 167 0.68:1

Generated by 🚫 dangerJS

@codecov
Copy link

codecov bot commented Sep 12, 2019

Codecov Report

Merging #1925 into master will increase coverage by 2.09%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1925      +/-   ##
==========================================
+ Coverage   77.02%   79.12%   +2.09%     
==========================================
  Files         158      156       -2     
  Lines        5459     4972     -487     
  Branches     1581     1479     -102     
==========================================
- Hits         4205     3934     -271     
+ Misses       1241     1025     -216     
  Partials       13       13
Impacted Files Coverage Δ
packages/react/src/lib/felaRenderer.tsx 76.92% <ø> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f0541bc...4a10940. Read the comment docs.

@layershifter
Copy link
Member Author

layershifter commented Sep 16, 2019

@jdhuntington
Copy link
Contributor

Closing as this has seen no activity for awhile. Please reopen if still relevant. Thanks!

felaPluginEmbedded(),
felaPluginPrefixer(),

felaExpandCssShorthandsPlugin(),
Copy link
Member Author

Choose a reason for hiding this comment

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

This move is valid as inline-style-expand-shorthand handles arrays on its side.

Copy link
Contributor

@mnajdova mnajdova Feb 26, 2020

Choose a reason for hiding this comment

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

How are we handling arrays exactly? As far as I can see, we are just spreading the array:

if (Array.isArray(cssPropertyValue)) {
    return { ...acc, [cssPropertyName]: cssPropertyValue }
}

Is the expandProperty function handling arrays?

Copy link
Member Author

Choose a reason for hiding this comment

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

expandProperty exactly, I added this functionality in robinweser/inline-style-expand-shorthand#13

@layershifter layershifter changed the title chore(fela): use Fela plugin to expand shorthands perf: use inline-style-expand-shorthand for expanding Feb 11, 2020
})
})

test('should expand handle "undefined" and "null"', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add test for the array value scenario?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure 🎸

Copy link
Member Author

Choose a reason for hiding this comment

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

Added 👍


// https://jsperf.com/array-indexof-vs-object-key-lookup2/12
const handledCssProps: Partial<Record<keyof CSS.Properties, true>> = {
// 'font', Oops, is not supported by inline-style-expand-shorthand
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add BREAKING CHANGE changelog entry

Copy link
Member Author

Choose a reason for hiding this comment

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

Added and updated PR's description

@layershifter layershifter merged commit e692213 into master Feb 26, 2020
@layershifter layershifter deleted the chore/use-fela-plugin branch February 26, 2020 10:56
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