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

Add Heimdall support #362

Merged
merged 1 commit into from
May 22, 2018
Merged

Add Heimdall support #362

merged 1 commit into from
May 22, 2018

Conversation

oligriffiths
Copy link
Contributor

@oligriffiths oligriffiths commented Apr 29, 2018

This PR adds heimdall stats support to Broccoli master.

This is ported from https://github.com/ember-cli/broccoli-builder
I've tried to setup the test in as close a representation to the original as possible.

What we're doing is registering the beginNode and endNode events to start/stop the heimdall timer, but these events are no longer "nested" as they are in Broccoli < 1.0. As a result, to get the nested structure that heimdall needs to do flame graphs, etc, we need to reconstruct this graph using the Broccoli node graph.

Additionally, because Broccoli re-uses nodes (for source directories), and heimdall does NOT allow you to have a node with multiple parents, we're simulating a new heimdall node, in the same way as we're doing it in Broccoli < 1.0 https://github.com/ember-cli/broccoli-builder/blob/0-18-x/lib/builder.js#L101-L107 => https://github.com/broccolijs/broccoli/pull/362/files#diff-dde50c51d91de11d407f53423f3baeecR399]]]

Here's a vis output (running BROCCOLI_VIZ=1 ember build) for broccoli 1.0 and current master for 2 builds:

I used ember-cli/broccoli-builder#27 for the broccoli-builder branch as this makes the labels more informative and closer to broccoli (which I think is good).

full - a regular build of ember on a fresh application
slim - a simple build (2 nodes and a merge)

Archive.zip

These can be uploaded to https://rwjblue.github.io/heimdalljs-visualizer

They produce the following results:

broccoli-full:

image
image

master-full:
image

image

broccoli-slim:

image

image

master-slim:

image

image

As you can see, both flame graphs are the same, and broccoli-1 is slightly faster

Note

There appears to be a bug in the ordering of the output in the flame graph, looking into it...

@rwjblue rwjblue requested a review from stefanpenner May 2, 2018 15:19
@@ -895,4 +900,113 @@ describe('Builder', function() {
});
});
});

describe('heimdall stats', function() {
it('produces stats', function(done) {
Copy link
Contributor

@stefanpenner stefanpenner May 2, 2018

Choose a reason for hiding this comment

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

let use mocha's built in promise support, rather then done. This way, error handling is handled for us by default in tests.

This looks like:

it('foo', function() {
  return promise.then(() => {});
});

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Cool. Will do.

@oligriffiths
Copy link
Contributor Author

@stefanpenner any idea how we can get the nested data for heidmall. Seems like it needs to be:

start(a)
start(b)
stop(b)
stop(a)

In order to make B a child of A.

Currently the node event system does

Start a
Stop a
Start b
Stop b

@stefanpenner
Copy link
Contributor

broccoli 1.0 no longer evaluates nodes recursively. Rather it essentially top-sorts the plugin graph ahead of time, and produces a linear array of nodeWrappers, related code:

broccoli/lib/builder.js

Lines 144 to 146 in 7d97eba

// This method recursively traverses the node graph and returns a nodeWrapper.
// The nodeWrapper graph parallels the node graph 1:1.
makeNodeWrapper(node, _stack) {

This nodeWrappers array is traversed, emitting the events between invocations of build, not as a parent of the recursive pattern from before.

What I am saying, is. The new pattern in broccoli is much nicer, but it does lose the parent/child hierarchy we had before, and thus may require a difference.

What likely could be done, is to emit as we do now. But ensure the start of a node, includes an array of ids for its inputs. Thoughts?

@oligriffiths
Copy link
Contributor Author

Yes that was the conclusion I came to. I think adding the parent ids to the entry and reconstructing the recursive output would be a good idea. I also notice that in the broccoli-builder implementation, the total time for each node is the self time plus the sum of the inputs, which we should also preserve. This would mean iterating the heidmall tree from top down. I can work this out.

@stefanpenner
Copy link
Contributor

Yes that was the conclusion I came to. I think adding the parent ids to the entry and reconstructing the recursive output would be a good idea. I also notice that in the broccoli-builder implementation, the total time for each node is the self time plus the sum of the inputs, which we should also preserve. This would mean iterating the heidmall tree from top down. I can work this out.

👍 1

@rwjblue can you confirm? This checks out for me.

@stefanpenner
Copy link
Contributor

@oligriffiths also if at anypoint I'm blocking some aspect of broccoli work, feel free to pester me via any medium until I unblock you.

@oligriffiths
Copy link
Contributor Author

@stefanpenner Super. Thanks

@oligriffiths oligriffiths changed the title [WIP] Add Heimdall support Add Heimdall support May 11, 2018
@stefanpenner
Copy link
Contributor

Its a bummer we have to do this, but as part of this step I don't see a good option. I do believe as part of the 1x series, we will re-invest in heimdall, to make it and broccoli better friends.

@rwjblue rwjblue merged commit a6139e4 into broccolijs:master May 22, 2018
@oligriffiths oligriffiths deleted the heimdall branch May 22, 2018 19:12
@krisselden
Copy link
Contributor

I actually find the current thing to be confusing because it makes the first parent look responsible for time it wasn't responsible for.

@oligriffiths
Copy link
Contributor Author

@krisselden yeah I agreee. Heimdall is not able to properly model the broccoli graph. The fact that broccoli-builder would make “fake” nodes in order to satisfy shared plugins shows that the model is incorrect.

Unfortunately heimdall would require a decent rewrite to support this, or something else entirely.

@krisselden
Copy link
Contributor

Not sure why it would model the broccoli graph, Id rather put inputBroccoli ids alongside broccoliId. Heimdal represnts what you’d put into a flame chart.

I hate that the visualizer now overweights the consuming node, it’s misleading.

@oligriffiths
Copy link
Contributor Author

@krisselden a flame graph can’t accurately model a broccoli tree due to the fact that nodes are shared between inputs. Source nodes for example are reused. Even broccoli-builder had this same issue.

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.

4 participants