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

refactor: use template strings, unify testing, remove dottie #10055

Merged
merged 5 commits into from
Oct 21, 2018

Conversation

SimonSchick
Copy link
Contributor

Pull Request check-list

Please make sure to review and check all of these items:

  • Does npm run test or npm run test-DIALECT pass with this change (including linting)?
  • Does the description below contain a link to an existing issue (Closes #[issue]) or a description of the issue you are solving?
  • Have you added new tests to prevent regressions?
  • Is a documentation update included (if this change modifies existing APIs, or introduces new ones)?
  • Did you follow the commit message conventions explained in CONTRIBUTING.md?

Description of change

Last big PR for a while.

  1. Used eslint to convert all string concat to template strings, see https://stackoverflow.com/questions/29055518/are-es6-template-literals-faster-than-string-concatenation
  2. Moved all usage of suite and test within tests to use the describe and it functions.
  3. Replaced dottie with _.set/get (one less dependency 🎉)

Copy link
Contributor

@sushantdhiman sushantdhiman left a comment

Choose a reason for hiding this comment

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

Please keep dottie dependency for now or atleast we will remove that in different PR. Dottie is used in some performance sensitive codebase. I want to measure the impace before we replace it with lodash get/set

@sushantdhiman
Copy link
Contributor

Some tests for Postgres are failing

@codecov
Copy link

codecov bot commented Oct 21, 2018

Codecov Report

Merging #10055 into master will decrease coverage by <.01%.
The diff coverage is 89.91%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #10055      +/-   ##
==========================================
- Coverage    96.3%    96.3%   -0.01%     
==========================================
  Files          63       63              
  Lines        9412     9410       -2     
==========================================
- Hits         9064     9062       -2     
  Misses        348      348
Impacted Files Coverage Δ
lib/associations/belongs-to-many.js 97.03% <ø> (ø) ⬆️
lib/associations/belongs-to.js 100% <ø> (ø) ⬆️
lib/associations/has-one.js 97.11% <ø> (ø) ⬆️
lib/associations/has-many.js 97.67% <ø> (ø) ⬆️
lib/dialects/abstract/connection-manager.js 87.6% <100%> (ø) ⬆️
lib/dialects/sqlite/query-interface.js 100% <100%> (ø) ⬆️
lib/dialects/mssql/data-types.js 98.13% <100%> (ø) ⬆️
lib/dialects/sqlite/data-types.js 97.15% <100%> (ø) ⬆️
lib/dialects/mssql/query.js 94.87% <100%> (ø) ⬆️
lib/dialects/sqlite/connection-manager.js 97.77% <100%> (ø) ⬆️
... and 24 more

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 be958ac...b17941c. Read the comment docs.

@SimonSchick
Copy link
Contributor Author

Re dottie, I did a rudimentary benchmark with 10mil iterations.

get
lodash: 2487.456ms
dottie: 1422.263ms
set
lodash: 2952.551ms
dottie: 2644.326ms

Reason I removed it is that you use _.get _.set everywhere else, not sure if the performance impact is relevant at all.

@sushantdhiman
Copy link
Contributor

We use lodash.get to merely get some deep config path, messages etc stuff, nothing critical. lodash.set is not used anywhere.

Dottie still got upper hand (as per your benchmark), I would like to measure impact at-least independently before deciding to remove it

@SimonSchick
Copy link
Contributor Author

I don't think it will have any measureable impact in actual consumer use but I will revert the specific changes.

Here is my benchmark:

'use strict';

const { get: lget, set: lset } = require('lodash');
const { get: dget, set: dset } = require('dottie');

console.log('get');
{
  const lookup = 'a.b.c.d.e.f.g';
  const obj = {
    a: {
      b: {
        d: {
          e: {
            f: {
              g: 123,
            },
          },
        },
      },
    },
  };
  console.time('lodash');
  for (let i = 0;i<10000000;++i) {
    lget(obj, lookup);
  }
  console.timeEnd('lodash');
}

{
  const lookup = 'a.b.c.d.e.f.g';
  const obj = {
    a: {
      b: {
        d: {
          e: {
            f: {
              g: 123,
            },
          },
        },
      },
    },
  };
  console.time('dottie');
  for (let i = 0;i<10000000;++i) {
    dget(obj, lookup);
  }
  console.timeEnd('dottie');
}

console.log('set');
{
  const lookup = 'a.b.c.d.e.f.g';
  const obj = {};
  console.time('lodash');
  for (let i = 0;i<10000000;++i) {
    lset(obj, lookup, 123);
  }
  console.timeEnd('lodash');
}

{
  const lookup = 'a.b.c.d.e.f.g';
  const obj = {};
  console.time('dottie');
  for (let i = 0;i<10000000;++i) {
    dset(obj, lookup);
  }
  console.timeEnd('dottie');
}

@sushantdhiman sushantdhiman merged commit a0545bf into sequelize:master Oct 21, 2018
@sushantdhiman
Copy link
Contributor

Thanks @SimonSchick

@SimonSchick SimonSchick deleted the refactor/more-cleanup branch October 21, 2018 15:37
owenkim pushed a commit to convoyinc/sequelize that referenced this pull request Sep 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants