Skip to content

Commit 670ddf3

Browse files
committed
perf fix for Duplex require replacement
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.
1 parent 775a098 commit 670ddf3

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

build/files.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,11 @@ const headRegexp = /(^module.exports = \w+;?)/m
3131
, '$1\n\n/*<replacement>*/\nvar Buffer = require(\'buffer\').Buffer;\n/*</replacement>*/\n'
3232
]
3333

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

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

0 commit comments

Comments
 (0)