module: significantly improve loader performance by BridgeAR · Pull Request #26970 · nodejs/node

@BridgeAR added module

Issues and PRs related to the module subsystem.

benchmark

Issues and PRs related to the benchmark subsystem.

labels

Mar 28, 2019

guybedford

guybedford

@BridgeAR BridgeAR added the author ready

PRs that have at least one approval, no pending requests for changes, and a CI started.

label

Mar 29, 2019

mscdex

jdalton

@BridgeAR

Add more benchmark options to properly verify the gains.

This makes sure the benchmark also tests requiring the same module
again instead of only loading each module only once.
Moving `try / catch` into separate functions is not necessary
anymore due to V8 optimizations.
This adds the `path` property to the module object. It contains the
current directory as path. That is necessary to add an extra caching
layer.

It also makes sure the `id` uses a default in case it's not set.
Otherwise the `path.dirname(id)` command could fail.
This adds an extra modules caching layer that operates on the parent's
`path` property and the current require argument. That together can
be used as unique identifier to speed up loading the same module more
than once. It is a cache on top of the current modules cache.

It has the nice feature that this cache does not only work in the same
file but it works for the whole current directory. So if the same file
is loaded in any other file from the same directory, it will also hit
this cache instead of having to resolve the file again.

To keep it backwards compatible with the old modules cache, it detects
invalidation of that cache.

mcollina

BridgeAR added a commit to BridgeAR/node that referenced this pull request

Apr 4, 2019
PR-URL: nodejs#26970
Refs: nodejs#25362
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>

BridgeAR added a commit to BridgeAR/node that referenced this pull request

Apr 4, 2019
This adds the `path` property to the module object. It contains the
current directory as path. That is necessary to add an extra caching
layer.

It also makes sure the `id` uses a default in case it's not set.
Otherwise the `path.dirname(id)` command could fail.

PR-URL: nodejs#26970
Refs: nodejs#25362
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>

BridgeAR added a commit to BridgeAR/node that referenced this pull request

Apr 4, 2019
This adds an extra modules caching layer that operates on the parent's
`path` property and the current require argument. That together can
be used as unique identifier to speed up loading the same module more
than once. It is a cache on top of the current modules cache.

It has the nice feature that this cache does not only work in the same
file but it works for the whole current directory. So if the same file
is loaded in any other file from the same directory, it will also hit
this cache instead of having to resolve the file again.

To keep it backwards compatible with the old modules cache, it detects
invalidation of that cache.

PR-URL: nodejs#26970
Refs: nodejs#25362
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>

Trott added a commit to Trott/io.js that referenced this pull request

Apr 4, 2019
A recent commit broke test-benchmark-module. This fixes it.

Culprit is nodejs#26970.

@Trott Trott mentioned this pull request

Apr 4, 2019

2 tasks

BethGriggs pushed a commit that referenced this pull request

Apr 9, 2019
PR-URL: #26970
Refs: #25362
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Signed-off-by: Beth Griggs <Bethany.Griggs@uk.ibm.com>

BethGriggs pushed a commit that referenced this pull request

Apr 9, 2019
Add more benchmark options to properly verify the gains.

This makes sure the benchmark also tests requiring the same module
again instead of only loading each module only once.

PR-URL: #26970
Refs: #25362
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Signed-off-by: Beth Griggs <Bethany.Griggs@uk.ibm.com>

BethGriggs pushed a commit that referenced this pull request

Apr 9, 2019
Moving `try / catch` into separate functions is not necessary
anymore due to V8 optimizations.

PR-URL: #26970
Refs: #25362
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Signed-off-by: Beth Griggs <Bethany.Griggs@uk.ibm.com>

BethGriggs pushed a commit that referenced this pull request

Apr 9, 2019
This adds the `path` property to the module object. It contains the
current directory as path. That is necessary to add an extra caching
layer.

It also makes sure the `id` uses a default in case it's not set.
Otherwise the `path.dirname(id)` command could fail.

PR-URL: #26970
Refs: #25362
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Signed-off-by: Beth Griggs <Bethany.Griggs@uk.ibm.com>

BethGriggs pushed a commit that referenced this pull request

Apr 9, 2019
This adds an extra modules caching layer that operates on the parent's
`path` property and the current require argument. That together can
be used as unique identifier to speed up loading the same module more
than once. It is a cache on top of the current modules cache.

It has the nice feature that this cache does not only work in the same
file but it works for the whole current directory. So if the same file
is loaded in any other file from the same directory, it will also hit
this cache instead of having to resolve the file again.

To keep it backwards compatible with the old modules cache, it detects
invalidation of that cache.

PR-URL: #26970
Refs: #25362
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Signed-off-by: Beth Griggs <Bethany.Griggs@uk.ibm.com>

BethGriggs pushed a commit that referenced this pull request

Apr 10, 2019
PR-URL: #26970
Refs: #25362
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Signed-off-by: Beth Griggs <Bethany.Griggs@uk.ibm.com>

BethGriggs pushed a commit that referenced this pull request

Apr 10, 2019
Add more benchmark options to properly verify the gains.

This makes sure the benchmark also tests requiring the same module
again instead of only loading each module only once.

PR-URL: #26970
Refs: #25362
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Signed-off-by: Beth Griggs <Bethany.Griggs@uk.ibm.com>

BethGriggs pushed a commit that referenced this pull request

Apr 10, 2019
Moving `try / catch` into separate functions is not necessary
anymore due to V8 optimizations.

PR-URL: #26970
Refs: #25362
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Signed-off-by: Beth Griggs <Bethany.Griggs@uk.ibm.com>

BethGriggs pushed a commit that referenced this pull request

Apr 10, 2019
This adds the `path` property to the module object. It contains the
current directory as path. That is necessary to add an extra caching
layer.

It also makes sure the `id` uses a default in case it's not set.
Otherwise the `path.dirname(id)` command could fail.

PR-URL: #26970
Refs: #25362
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Signed-off-by: Beth Griggs <Bethany.Griggs@uk.ibm.com>

BethGriggs pushed a commit that referenced this pull request

Apr 10, 2019
This adds an extra modules caching layer that operates on the parent's
`path` property and the current require argument. That together can
be used as unique identifier to speed up loading the same module more
than once. It is a cache on top of the current modules cache.

It has the nice feature that this cache does not only work in the same
file but it works for the whole current directory. So if the same file
is loaded in any other file from the same directory, it will also hit
this cache instead of having to resolve the file again.

To keep it backwards compatible with the old modules cache, it detects
invalidation of that cache.

PR-URL: #26970
Refs: #25362
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Signed-off-by: Beth Griggs <Bethany.Griggs@uk.ibm.com>

@BridgeAR BridgeAR deleted the improve-loader-performance branch

January 20, 2020 11:59

aduh95 added a commit to aduh95/node that referenced this pull request

May 9, 2020

addaleax pushed a commit that referenced this pull request

May 19, 2020
Refs: #26970
Fixes: #33270

PR-URL: #33323
Reviewed-By: Anna Henningsen <anna@addaleax.net>

codebytere pushed a commit that referenced this pull request

May 21, 2020
Refs: #26970
Fixes: #33270

PR-URL: #33323
Reviewed-By: Anna Henningsen <anna@addaleax.net>

codebytere pushed a commit that referenced this pull request

Jun 7, 2020
Refs: #26970
Fixes: #33270

PR-URL: #33323
Reviewed-By: Anna Henningsen <anna@addaleax.net>

codebytere pushed a commit that referenced this pull request

Jun 9, 2020
Refs: #26970
Fixes: #33270

PR-URL: #33323
Reviewed-By: Anna Henningsen <anna@addaleax.net>

QwireyInc pushed a commit to QwireyInc/node that referenced this pull request

Apr 19, 2025