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

Optimized changedKeys. #953

Merged
merged 1 commit into from
May 12, 2021
Merged

Optimized changedKeys. #953

merged 1 commit into from
May 12, 2021

Conversation

radekmie
Copy link
Contributor

@radekmie radekmie commented May 10, 2021

This is the third and probably the last PR focused on optimizing one hottest functions, at least for now. Here I focused on changedKeys. On the benchmark I prepared, the time dropped from 626ms down to 247ms, which makes almost 60% improvement. Additionally, we no longer rely on xorWith, making the bundle slightly smaller.

The only downside is that the implementation is now slightly more complex, but I find it more verbose than the current one.

Benchmark
describe('benchmark', () => {
  it.each(Array.from({ length: 25 }, (_, x) => x + 1))('is fast %i', () => {
    expect(true).toBe(true);
    for (let index = 0; index < 5000; ++index) {
      changedKeys('a', [], []);
      changedKeys('a', [1], [1]);
      changedKeys('a', [1, 2], [1, 2]);
      changedKeys('a', new Date(10), new Date(10));
      changedKeys('a', new Date(20), new Date(20));
      changedKeys('a', new Date(30), new Date(30));
      changedKeys('a', {}, {});
      changedKeys('a', { a: 1 }, { a: 1 });
      changedKeys('a', { a: 1, b: 2 }, { a: 1, b: 2 });
      changedKeys('a', 1, 1);
      changedKeys('a', null, null);
      changedKeys('a', true, true);
      changedKeys('a', 'no', 'no');
      changedKeys('a', [], [1]);
      changedKeys('a', [1], [1, 2]);
      changedKeys('a', [1, 2], [1, 2, 3]);
      changedKeys('a', new Date(10), new Date(20));
      changedKeys('a', new Date(20), new Date(30));
      changedKeys('a', new Date(30), new Date(40));
      changedKeys('a', {}, { a: 1 });
      changedKeys('a', { a: 1 }, { a: 1, b: 2 });
      changedKeys('a', { a: 1, b: 2 }, { a: 1, b: 2, c: 3 });
      changedKeys('a', 1, 2);
      changedKeys('a', null, true);
      changedKeys('a', true, null);
      changedKeys('a', 'no', 'pe');
      changedKeys('a', [1]);
      changedKeys('a', [1], []);
      changedKeys('a', [1, 2], [1]);
      changedKeys('a', [1, 2, 3], [1, 2]);
      changedKeys('a', new Date(20));
      changedKeys('a', new Date(20), new Date(10));
      changedKeys('a', new Date(30), new Date(20));
      changedKeys('a', new Date(40), new Date(30));
      changedKeys('a', { a: 1 });
      changedKeys('a', { a: 1 }, {});
      changedKeys('a', { a: 1, b: 2 }, { a: 1 });
      changedKeys('a', { a: 1, b: 2, c: 3 }, { a: 1, b: 2 });
      changedKeys('a', 2);
      changedKeys('a', 2, 1);
      changedKeys('a', true, null);
      changedKeys('a', null, true);
      changedKeys('a', 'pe', 'no');
    }
  });
});

@radekmie radekmie added the Type: Feature New features and feature requests label May 10, 2021
@radekmie radekmie added this to the v3.5 milestone May 10, 2021
@radekmie radekmie added this to Review in Open Source (migrated) via automation May 10, 2021
@codecov
Copy link

codecov bot commented May 10, 2021

Codecov Report

Merging #953 (ca2da5b) into master (06f0aa6) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #953   +/-   ##
=======================================
  Coverage   98.82%   98.82%           
=======================================
  Files         202      202           
  Lines        3144     3149    +5     
  Branches      791      793    +2     
=======================================
+ Hits         3107     3112    +5     
  Misses          1        1           
  Partials       36       36           
Impacted Files Coverage Δ
packages/uniforms/src/changedKeys.ts 100.00% <100.00%> (ø)

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 06f0aa6...ca2da5b. Read the comment docs.

@radekmie radekmie merged commit 97e3869 into master May 12, 2021
Open Source (migrated) automation moved this from Review to Closed May 12, 2021
@radekmie radekmie deleted the optimized-changedkeys branch May 12, 2021 12:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Feature New features and feature requests
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

3 participants