Skip to content

Commit

Permalink
perf fix for Duplex require replacement
Browse files Browse the repository at this point in the history
I was noticing that RegExps called from Module._resolveLookupPaths were getting
to be the hottest symbol in some profiles. readable-stream seems to be requiring
Duplex from inside functions. It would be faster to not do a require on each
invocation of Readable, ReadableState, Writable, WritableState.
  • Loading branch information
ofrobots committed Nov 26, 2015
1 parent 775a098 commit 670ddf3
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion build/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ const headRegexp = /(^module.exports = \w+;?)/m
, '$1\n\n/*<replacement>*/\nvar Buffer = require(\'buffer\').Buffer;\n/*</replacement>*/\n'
]

// The browser build ends up with a circular dependency, so the require is
// done lazily, but cached.
, addDuplexRequire = [
/^(function (?:Writable|Readable)(?:State)?.*{)/gm
, '$1\n var Duplex = require(\'./_stream_duplex\');\n'
, 'var Duplex;\n$1\n Duplex = Duplex || require(\'./_stream_duplex\');\n'
]

, altForEachImplReplacement = require('./common-replacements').altForEachImplReplacement
Expand Down

0 comments on commit 670ddf3

Please sign in to comment.