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 joinName. #935

Merged
merged 1 commit into from
Apr 21, 2021
Merged

Optimized joinName. #935

merged 1 commit into from
Apr 21, 2021

Conversation

radekmie
Copy link
Contributor

This PR optimizes the joinName helper without affecting its functionality. On the presented benchmark, the performance improved from 217ms to 79ms (best time out of 25 runs).

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) {
      joinName(null);
      joinName(null, 'a');
      joinName(null, 'a', 'b');
      joinName(null, 'a', 'b', null);
      joinName(null, 'a', 'b', null, 0);
      joinName(null, 'a', 'b', null, 1);
      joinName(['a'], 'b');
      joinName('a', ['b']);
      joinName('', 'a', 'b');
      joinName('a', '', 'b');
      joinName('a', 'b', '');
      joinName('a', null, 'b');
      joinName('a', false, 'b');
      joinName('a', undefined, 'b');
      joinName(0, 'a', 'b');
      joinName('a', 0, 'b');
      joinName('a', 'b', 0);
      joinName(1, 'a', 'b');
      joinName('a', 1, 'b');
      joinName('a', 'b', 1);
      joinName('a', 'b.c.d');
      joinName('a.b', 'c.d');
      joinName('a.b.c', 'd');
      joinName(null, 'a', 'b.c.d');
      joinName(null, 'a.b', 'c.d');
      joinName(null, 'a.b.c', 'd');
    }
  });
});

@radekmie radekmie added the Type: Feature New features and feature requests label Apr 20, 2021
@radekmie radekmie added this to the v3.4 milestone Apr 20, 2021
@radekmie radekmie requested review from Monteth and wadamek65 April 20, 2021 12:36
@codecov
Copy link

codecov bot commented Apr 20, 2021

Codecov Report

Merging #935 (044f8d5) into master (3a559de) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #935   +/-   ##
=======================================
  Coverage   97.44%   97.44%           
=======================================
  Files         202      202           
  Lines        3912     3920    +8     
  Branches      798      801    +3     
=======================================
+ Hits         3812     3820    +8     
  Misses         11       11           
  Partials       89       89           
Impacted Files Coverage Δ
packages/uniforms/src/joinName.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 3a559de...044f8d5. Read the comment docs.

@radekmie radekmie merged commit d079e7a into master Apr 21, 2021
@radekmie radekmie deleted the optimized-joinname branch April 21, 2021 13:28
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.

3 participants