Skip to content

Commit

Permalink
feat(reporter): Replace way-too-big memoizee with a trivial solution.
Browse files Browse the repository at this point in the history
The reporter functionality was pulling the entire memoizee library with all its
dependencies for a simple memoization solution, and using almost none of the
functionality. This seems like not the most critically performant codepath. This
PR replaces that with a good-case solution that lowers the dependency footprint.

Version 2: WeakMap.
  • Loading branch information
DavidSouther committed Oct 13, 2015
1 parent 3ca7d2f commit d926fe3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
14 changes: 10 additions & 4 deletions lib/reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ var log = require('./logger').create('reporter')
var MultiReporter = require('./reporters/multi')
var baseReporterDecoratorFactory = require('./reporters/base').decoratorFactory
var SourceMapConsumer = require('source-map').SourceMapConsumer
var memoizeWeak = require('memoizee/weak')
var WeakMap = require('core-js/es6/weak-map')

var createErrorFormatter = function (basePath, emitter, SourceMapConsumer) {
var lastServedFiles = []
Expand All @@ -29,9 +29,15 @@ var createErrorFormatter = function (basePath, emitter, SourceMapConsumer) {
'(\\:(\\d+))?' + // column
'', 'g')

var getSourceMapConsumer = memoizeWeak(function (sourceMap) {
return new SourceMapConsumer(sourceMap)
})
var getSourceMapConsumer = (function () {
var cache = new WeakMap()
return function (sourceMap) {
if (!cache.has(sourceMap)) {
cache.set(sourceMap, new SourceMapConsumer(sourceMap))
}
return cache.get(sourceMap)
}
}())

return function (msg, indentation) {
// remove domain and timestamp from source files
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,6 @@
"http-proxy": "^1.11.1",
"lodash": "^3.8.0",
"log4js": "^0.6.25",
"memoizee": "^0.3.8",
"mime": "^1.3.4",
"minimatch": "^2.0.7",
"optimist": "^0.6.1",
Expand Down

0 comments on commit d926fe3

Please sign in to comment.