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

Memoize names (increases speed by 10x) #280

Merged
merged 3 commits into from
May 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion benchmarks/runtime.bench.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ function lintManyFilesWithAllRecommendedRules({ numberOfFiles }) {
describe('runtime', () => {
it('should not take longer as the defined budget to lint many files with the recommended config', () => {
const nodeVersionMultiplier = getNodeVersionMultiplier();
const budget = 70000000 / cpuSpeed * nodeVersionMultiplier;
const budget = 7000000 / cpuSpeed * nodeVersionMultiplier;

const { medianDuration } = runBenchmark(() => {
lintManyFilesWithAllRecommendedRules({ numberOfFiles: 350 });
Expand Down
7 changes: 5 additions & 2 deletions lib/util/names.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const map = require('ramda/src/map');
const view = require('ramda/src/view');
const assoc = require('ramda/src/assoc');
const allPass = require('ramda/src/allPass');
const memoizeWith = require('ramda/src/memoizeWith');

const INTERFACES = {
BDD: 'BDD',
Expand Down Expand Up @@ -115,12 +116,14 @@ function getNamesByType(type, filterOptions = {}) {
return extractNames(filteredNames);
}

const getNamesByTypeMemoized = memoizeWith((type, options) => JSON.stringify({ type, options }), getNamesByType);

function getTestCaseNames(options) {
return getNamesByType(TYPES.testCase, options);
return getNamesByTypeMemoized(TYPES.testCase, options);
}

function getSuiteNames(options) {
return getNamesByType(TYPES.suite, options);
return getNamesByTypeMemoized(TYPES.suite, options);
}

module.exports = {
Expand Down
16 changes: 0 additions & 16 deletions test/util/namesSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,6 @@ describe('mocha names', () => {
expect(testCaseNames).to.deep.equal([]);
});

it('always returns a new array', () => {
const testCaseNames1 = getTestCaseNames({ modifiersOnly: true });
const testCaseNames2 = getTestCaseNames({ modifiersOnly: true });

expect(testCaseNames1).to.deep.equal(testCaseNames2);
expect(testCaseNames1).to.not.equal(testCaseNames2);
});

it('ignores invalid modifiers', () => {
const testCaseNames = getTestCaseNames({ modifiers: [ 'foo' ], modifiersOnly: true });

Expand Down Expand Up @@ -185,14 +177,6 @@ describe('mocha names', () => {
expect(suiteNames).to.deep.equal([]);
});

it('always returns a new array', () => {
const suiteNames1 = getSuiteNames({ modifiersOnly: true });
const suiteNames2 = getSuiteNames({ modifiersOnly: true });

expect(suiteNames1).to.deep.equal(suiteNames2);
expect(suiteNames1).to.not.equal(suiteNames2);
});

it('ignores invalid modifiers', () => {
const suiteNames = getSuiteNames({ modifiers: [ 'foo' ], modifiersOnly: true });

Expand Down