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

perf: use Object.assign in @babel/plugin-proposal-object-rest-spread #1895

Merged
merged 4 commits into from
Sep 6, 2019

Conversation

layershifter
Copy link
Member

@layershifter layershifter commented Sep 6, 2019

Thanks to Mario Baricevic for pointing to this.

馃悽 Issue

We use @babel-preset-env to transform our code.

According to .browserslistrc it will compile our code to be used in IE11, there are no support for Object.assign() or object spread and it means that Babel helper will be used. However, we have already required Object.assign() polyfill and it means that we can use it instead of Babel helper.

Example input

const a = { foo: 'bar'}
const b = { baz: 'qux'}
const c = { ...a, ...b }

Example output before

import _objectSpread from "@babel/runtime/helpers/esm/objectSpread";
var a = { foo: 'bar' };
var b = { baz: 'qux' };
var c = _objectSpread({}, a, b);

@babel/runtime/helpers/esm/objectSpread.js contains own implementation which is definitely slower.

Example output with { loose: true, useBuiltIns: true }

var a = { foo: 'bar' };
var b = { baz: 'qux' };
var c = Object.assign({}, a, b);

馃弫 Measures

cross-env PERF=true gulp perf --filter *Chat.perf.tsx --times=100

I run the command above 4 times to test changes. During each sample run perf example was run 100 times.

Performance win is around 13%, see results below.

Before

Example Avg Median
Chat.perf.tsx (Sample 1) 576.69 575.25
Chat.perf.tsx (Sample 2) 583.62 577.66
Chat.perf.tsx (Sample 3) 588.64 580.58
Chat.perf.tsx (Sample 4) 578.11 575.83
Total 581.765

After

Example Avg Median
Example Avg Median
Chat.perf.tsx (Sample 1) 504.76 503.9
Chat.perf.tsx (Sample 2) 507.85 505.52
Chat.perf.tsx (Sample 3) 505.25 504.13
Chat.perf.tsx (Sample 4) 513.71 507.39
Total 507.8925

@codecov
Copy link

codecov bot commented Sep 6, 2019

Codecov Report

Merging #1895 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@          Coverage Diff           @@
##           master   #1895   +/-   ##
======================================
  Coverage    69.9%   69.9%           
======================================
  Files         888     888           
  Lines        7775    7775           
  Branches     2244    2244           
======================================
  Hits         5435    5435           
  Misses       2330    2330           
  Partials       10      10

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 0347c18...15d75ad. Read the comment docs.

@@ -28,7 +28,7 @@ const ChatExample = () => {
}}
>
<Chat
items={_.times(30, i => ({
items={_.times(100, i => ({
Copy link
Member Author

Choose a reason for hiding this comment

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

Adjusted to have cleaner results.

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.

None yet

2 participants