Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use a more appropriate data structure for nodeWrappers. #418

Merged
merged 1 commit into from
Aug 1, 2019

Conversation

stefanpenner
Copy link
Contributor

@stefanpenner stefanpenner commented Jul 25, 2019

Use a more appropriate data structure for nodeWrappers.

Since NodeWrappers lists:

  • must be insertion ordered
  • must contain only unique values (based on their key)
  • support a fast existence / lookup operation

This PR switches it from an array to a map.

As broccoli pipelines grow large, simply searching the array to detect duplicates on insertion can become very costly, and switching to a Map addresses this specific bottleneck.

@stefanpenner stefanpenner changed the title Use map instead of array for storing the nodeWrappers. This prevents … Choose better data structure for nodeWrappers. Jul 26, 2019
@stefanpenner stefanpenner changed the title Choose better data structure for nodeWrappers. Use a more appropriate data structure for nodeWrappers. Jul 26, 2019
@stefanpenner
Copy link
Contributor Author

I think we should also add heimdall instrumentation for https://github.com/broccolijs/broccoli/blob/master/lib/builder.js#L170

@@ -143,8 +143,11 @@ module.exports = class Builder extends EventEmitter {
this.buildHeimdallTree(outputNodeWrapper);
}),
() => {
let buildsSkipped = this.nodeWrappers.filter(nw => nw.buildState.built === false).length;
logger.debug(`Total nodes skipped: ${buildsSkipped} out of ${this.nodeWrappers.length}`);
let buildsSkipped = filterMap(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note for a future iteration: it would be really nice if heimdall-logger provided a way to conditionally emit logging info. Right now we are forced to eagerly calculate the debugging output when in 99% of the time its never consumed / reviewed.

lib/builder.js Outdated Show resolved Hide resolved
Since NodeWrappers lists:

* must be insertion ordered
* must contain only unique values (based on their key)
* support a fast existence / lookup operation

This PR switches it from an array to a map.

As broccoli pipelines grow large, simply searching the array to detect duplicates on insertion can become very costly, and switching to a Map addresses this specific bottleneck.
@stefanpenner stefanpenner merged commit c9d7b65 into master Aug 1, 2019
@stefanpenner stefanpenner deleted the fix-algo branch August 1, 2019 16:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants