Skip to content

Commit

Permalink
Do not put modules in pending list if they have been finalized
Browse files Browse the repository at this point in the history
With the 2 pass approach to finding deps and evaluating them squentially, we are putting modules that have already been evaluated as well. This is not needed since when the module is read from the pending queue, it will return. However, we do not really need to push it in the pending queue and then know if it was finalized.

This is a minor optimization to the pending queue.
  • Loading branch information
kratiahuja committed Jun 21, 2016
1 parent aee4a0e commit cff26f8
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 26 deletions.
6 changes: 3 additions & 3 deletions benchmarks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@ note: these benchmarks run in seperate processes, the idea is to similate
initial load + use, not after the JIT has settled

```sh
env NODE_ENV=production node runner.js ./benchmarks/scenarios/<name of scenario>
env NODE_ENV=production node ./benchmarks/runner.js ./benchmarks/scenarios/<name of scenario>
```

If you want to run in a single process, to easily debug or run a profiler the
`run-once.js` should be considered

```sh
env NODE_ENV=production node run-once.js ./benchmarks/scenarios/<name of scenario>
env NODE_ENV=production node ./benchmarks/run-once.js ./benchmarks/scenarios/<name of scenario>
```

Running with the profiler:

```sh
env NODE_ENV=production node --prof run-once.js ./benchmarks/scenarios/<name of scenario>
env NODE_ENV=production node --prof ./benchmarks/run-once.js ./benchmarks/scenarios/<name of scenario>

# to view the output:
node --prof-process isolate-0x<name of file>
Expand Down
7 changes: 5 additions & 2 deletions lib/loader/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,13 @@ var loader, define, requireModule, require, requirejs;
resolve: 0,
resolveRelative: 0,
findModule: 0,
pendingQueueLength: 0
};
requirejs._stats = stats;
}

var stats;

resetStats();

loader = {
Expand Down Expand Up @@ -81,7 +83,7 @@ var loader, define, requireModule, require, requirejs;
var defaultDeps = ['require', 'exports', 'module'];

function Module(name, deps, callback, alias) {
stats.modules ++;
stats.modules++;
this.id = uuid++;
this.name = name;
this.deps = !deps.length && callback.length ? defaultDeps : deps;
Expand Down Expand Up @@ -222,9 +224,10 @@ var loader, define, requireModule, require, requirejs;

if (!mod) { missingModule(name, referrer); }

if (pending) {
if (pending && !mod.finalized) {
mod.findDeps(pending);
pending.push(mod);
stats.pendingQueueLength++;
}
return mod;
}
Expand Down
Loading

0 comments on commit cff26f8

Please sign in to comment.