From f2b2b41812d4ea806e0fa5b2d366b36e02cc6b48 Mon Sep 17 00:00:00 2001 From: Matt Bierner Date: Tue, 17 May 2016 16:47:55 -0700 Subject: [PATCH 1/2] Limit Depth of created dependecy nodes This PR further addresses memory usage. **Bug** Right now, we end up parsing the entire node dependecy tree and creating objects to represent every dependency in it. This uses a lot of memory and a lot of time during boot. The use of this is that we allow users to explore the entire module dependency tree in VS directly. **Fix** These operations are negatively impacting user experiance, especially when loading projects with lots of dependencies (such as the eslint source). I also am not convinced that seeing the dependencies of your project dependenices is actually useful, at least 99.99% of the the time. This fix limits the depth to which we create dependency nodes to 1 (only root deps). Memory usage and boot time are much improved. --- Nodejs/Product/Npm/SPI/NodeModules.cs | 11 ++++++++--- Nodejs/Product/Npm/SPI/RootPackage.cs | 5 +++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/Nodejs/Product/Npm/SPI/NodeModules.cs b/Nodejs/Product/Npm/SPI/NodeModules.cs index ec36c0644..2eedf861e 100644 --- a/Nodejs/Product/Npm/SPI/NodeModules.cs +++ b/Nodejs/Product/Npm/SPI/NodeModules.cs @@ -22,14 +22,19 @@ namespace Microsoft.NodejsTools.Npm.SPI { internal class NodeModules : AbstractNodeModules { - private Dictionary _allModules; private static readonly string[] _ignoredDirectories = { @"\.bin", @"\.staging" }; - public NodeModules(IRootPackage parent, bool showMissingDevOptionalSubPackages, Dictionary allModulesToDepth = null, int depth = 0) { - var modulesBase = Path.Combine(parent.Path, NodejsConstants.NodeModulesFolder); + private readonly Dictionary _allModules; + public NodeModules(IRootPackage parent, bool showMissingDevOptionalSubPackages, Dictionary allModulesToDepth = null, int depth = 0, int maxDepth = 1) { _allModules = allModulesToDepth ?? new Dictionary(); + //if (depth >= maxDepth) { + // return; + // } + + var modulesBase = Path.Combine(parent.Path, NodejsConstants.NodeModulesFolder); + // This is the first time NodeModules is being created. // Iterate through directories to add everything that's known to be top-level. if (depth == 0) { diff --git a/Nodejs/Product/Npm/SPI/RootPackage.cs b/Nodejs/Product/Npm/SPI/RootPackage.cs index cd89507b1..7e1aadfa4 100644 --- a/Nodejs/Product/Npm/SPI/RootPackage.cs +++ b/Nodejs/Product/Npm/SPI/RootPackage.cs @@ -25,7 +25,8 @@ public RootPackage( string fullPathToRootDirectory, bool showMissingDevOptionalSubPackages, Dictionary allModules = null, - int depth = 0) { + int depth = 0, + int maxDepth = 1) { Path = fullPathToRootDirectory; var packageJsonFile = System.IO.Path.Combine(fullPathToRootDirectory, "package.json"); try { @@ -45,7 +46,7 @@ public RootPackage( } try { - Modules = new NodeModules(this, showMissingDevOptionalSubPackages, allModules, depth); + Modules = new NodeModules(this, showMissingDevOptionalSubPackages, allModules, depth, maxDepth); } catch (PathTooLongException) { // otherwise we fail to create it completely... } From 96f340cf4568d188072d7408d7d1a3e07f7ec667 Mon Sep 17 00:00:00 2001 From: Matt Bierner Date: Tue, 17 May 2016 17:00:28 -0700 Subject: [PATCH 2/2] Change works better when it's not commented out :) --- Nodejs/Product/Npm/SPI/NodeModules.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Nodejs/Product/Npm/SPI/NodeModules.cs b/Nodejs/Product/Npm/SPI/NodeModules.cs index 2eedf861e..1f3d064d6 100644 --- a/Nodejs/Product/Npm/SPI/NodeModules.cs +++ b/Nodejs/Product/Npm/SPI/NodeModules.cs @@ -29,9 +29,9 @@ internal class NodeModules : AbstractNodeModules { public NodeModules(IRootPackage parent, bool showMissingDevOptionalSubPackages, Dictionary allModulesToDepth = null, int depth = 0, int maxDepth = 1) { _allModules = allModulesToDepth ?? new Dictionary(); - //if (depth >= maxDepth) { - // return; - // } + if (depth >= maxDepth) { + return; + } var modulesBase = Path.Combine(parent.Path, NodejsConstants.NodeModulesFolder);