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

fix(perf): cache this.exclude.shouldInstrument for improved performance #388

Merged
merged 4 commits into from
Apr 20, 2022
Merged
Changes from 1 commit
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
22 changes: 20 additions & 2 deletions lib/report.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class Report {
excludeNodeModules: excludeNodeModules
})
this.excludeAfterRemap = excludeAfterRemap
this.shouldInstrumentCache = new Map()
this.omitRelative = omitRelative
this.sourceMapCache = {}
this.wrapperLength = wrapperLength
Expand Down Expand Up @@ -96,7 +97,7 @@ class Report {
const path = resolve(this.resolve, v8ScriptCov.url)
const converter = v8toIstanbul(path, this.wrapperLength, sources, (path) => {
if (this.excludeAfterRemap) {
return !this.exclude.shouldInstrument(path)
return !this._shouldInstrument(path)
}
})
await converter.load()
Expand Down Expand Up @@ -287,7 +288,7 @@ class Report {
}
}
if ((!this.omitRelative || isAbsolute(v8ScriptCov.url))) {
if (this.excludeAfterRemap || this.exclude.shouldInstrument(v8ScriptCov.url)) {
if (this.excludeAfterRemap || this._shouldInstrument(v8ScriptCov.url)) {
result.push(v8ScriptCov)
}
}
Expand All @@ -311,6 +312,23 @@ class Report {
}
return cache
}

/**
* this.exclude.shouldInstrument with cache
*
* @private
* @return {boolean}
*/
_shouldInstrument (filename) {
const cacheResult = this.shouldInstrumentCache.get(filename)
if (cacheResult !== undefined) {
return cacheResult
}

const result = this.exclude.shouldInstrument(filename)
this.shouldInstrumentCache.set(filename, result)
return result
}
}

module.exports = function (opts) {
Expand Down