-
Notifications
You must be signed in to change notification settings - Fork 318
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
Delegate the generation of the dependency tree to an external module? #68
Comments
Hi and thanks! This is something I've wanted to do for a long time since madge has grown to do a lot more than it was intended to do. As you say, I built it mainly for visualizing and find circular dependencies. It sounds very appealing to move out the generation of the dependency tree to a standalone module and I'm open to use your module if it solves the problem :-) Do you have the insight you need to madge to make a PR? Or do you want me to have a look at it? |
I don't have the entire context around the inner workings of madge, so you'd know best as to the architectural changes necessary for the move and any feature regressions that would be caused by the effort. I'll have a look this weekend. In the meantime, I'm more than happy to help answer questions about dependency-tree or discuss what's needed in this thread.
dependency-tree has the information that would allow us to deduce circular dependencies. If module
where we can cross-reference a module's dependency with that dependency's dependency list to see if the current module is a member. That should be a constant-time lookup. |
I'll look into it as soon as possible. I'm away the entire weekend, but hopefully I'll get some free time next week. |
I'll take look at this soon :-) I'm planning to do some refactoring of Madge and would love to fix this then. |
I built a proof of concept to see how it would work: https://github.com/dependents/node-tree-pic. One big thing is that dependency-tree needs a flag to stop traversing into node_modules. |
I've tried out |
Thanks @pahen! :) Happy to help add any functionality or fixes at the dependency-tree layer and below. Also happy to discuss any of the breaking changes to see if there's a path forward. I remember thinking that https://github.com/mrjoelkemp/node-dependents was similar to one of madge's features that dependency-tree wouldn't provide. There might be a middle ground. Super excited to see this integration. Thanks for your effort! |
I'm at the final stages of 1.0 and has began to do some testing and have some concerns about the performance. I expected it to be a little slower since we do much more AST stuff now but it's a pretty big difference. Here's the numbers on 3 different projects. Do you have any thoughts on this @mrjoelkemp? Any plans for improvements in CommonJS (https://github.com/eslint/eslint)
AMD (https://github.com/adobe/brackets)
ES6 (https://github.com/kentcdodds/es6-todomvc)
|
Hey @pahen! Congrats on finishing the first release candidate of 1.0! 🎉 Could you also include the time that it takes for dependency tree alone to run on those files? This way we can separate dependency-tree's runtime from the application code changes in madge v1. There's a dependency-tree binary that you can run from the cli directly. It doesn't have support for a I'd be curious to see how perf changes if we replace the module type sniff in precinct with the regex checks that you were doing before to determine if a file was amd, cjs, or es6.
Would you be able to replace the module type sniff with a regex (hacking it within your node_modules is fine for this experiment) and report the performance change? I could try working on that tonight or tomorrow night if you'd like. If the above experiment isn't fruitful, I'll have to do a deep dive in profiling all of the operations of dependency-tree to see what's causing the slowdown. |
Thanks! :) Here's the time it takes for dependency-tree cli to run directly on the eslint project with node_modules excluded:
real 0m7.867s So it seems madge isn't adding much overhead. I'll do some deep dive and see if I can find out what taking most of the time. But it would be nice if you could take a dive too :) |
Hardcoding |
This is very helpful when profiling if you haven't tried it yet @mrjoelkemp |
It's quite interesting that it takes 550ms before Node.js has completed the startup process. I believe that has to do with the amount of modules in use. |
One fix to dramatically improve performance dependents/module-definition#23 🎉 |
One more issue found. See dependents/node-dependency-tree#43 |
Thanks again for your great work in tracking down these optimizations. Now that dependents/node-dependency-tree#43 has been fixed, can you please post the new perf stats to see how we did? |
You're welcome! Always satisfying to improve performance :) Here's the new stats: CommonJS (https://github.com/eslint/eslint) 4x faster! AMD (https://github.com/adobe/brackets) 2x faster! ES6 (https://github.com/kentcdodds/es6-todomvc) 1,5x faster! |
So awesome! Thanks for the stats! :) |
@pahen The simple perf improvement in dependents/node-source-walk#17 shaves off a few seconds from dependency-tree's runtime:
I cut a patch on node-source-walk, so all users should see this with a fresh npm install. 👯 |
That's awesome Joel :) Another great find in the hunt for blazing speed! 🎉 Did you found that slow iteration by profiling? |
Thanks! Yes, I used node-nightly and even node's --prof flag to identify the hot spot. Sadly, some of the babylon plugins like object spread are adding more than a half second in overall runtime. There's room to optimize those plugins, I assume. |
Big fan of madge! Thanks for the great work.
Semantically, it seems like madge is a visualization layer of an app's dependency tree. The generation of the tree is also done within madge though.
I wrote https://github.com/mrjoelkemp/node-dependency-tree as a way to generate the dependency tree of any JS codebase (amd, cjs, es6). It outputs a nested JSON structure (or a list of visited files) representing the tree of a file. Is there any interest in using that to power madge?
Thanks for your time.
The text was updated successfully, but these errors were encountered: