Skip to content

Commit d3c0297

Browse files
committed
Move RequireAnalysisUnit instantiation to TreeUpdateAnalysis so that it is
called on the analysis thread.
1 parent 1107227 commit d3c0297

3 files changed

Lines changed: 33 additions & 24 deletions

File tree

Nodejs/Product/Analysis/Analysis/AnalysisLog.cs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -87,19 +87,17 @@ private void Add(string Event, params object[] Args) {
8787
int max = MaxItems;
8888

8989
if (max != 0) {
90-
lock (LogItems) {
91-
if (LogItems.Count >= max) {
92-
while (LogItems.Count > max) {
93-
// if the queue was set to shrink remove any old items.
94-
LogItems.PopLeft();
95-
}
96-
if (LogIndex >= max) {
97-
LogIndex = 0;
98-
}
99-
LogItems[LogIndex++] = new LogItem { Time = Time, Event = Event, Args = Args };
100-
} else {
101-
LogItems.Append(new LogItem { Time = Time, Event = Event, Args = Args });
90+
if (LogItems.Count >= max) {
91+
while (LogItems.Count > max) {
92+
// if the queue was set to shrink remove any old items.
93+
LogItems.PopLeft();
10294
}
95+
if (LogIndex >= max) {
96+
LogIndex = 0;
97+
}
98+
LogItems[LogIndex++] = new LogItem { Time = Time, Event = Event, Args = Args };
99+
} else {
100+
LogItems.Append(new LogItem { Time = Time, Event = Event, Args = Args });
103101
}
104102
}
105103
}

Nodejs/Product/Analysis/Analysis/Analyzer/AnalysisUnit.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ namespace Microsoft.NodejsTools.Analysis {
3232
/// Our dependency tracking scheme works by tracking analysis units - when we add a dependency it is the current
3333
/// AnalysisUnit which is dependent upon the variable. If the value of a variable changes then all of the dependent
3434
/// AnalysisUnit's will be re-enqueued. This proceeds until we reach a fixed point.
35+
///
36+
/// Note that AnalysisUnit contructors / methods are not threadsafe because we expect there to be many AnalysisUnits,
37+
/// and we want to keep things as performant as possible (which means minimizing locking behavior and whatnot.)
3538
/// </summary>
3639
[Serializable]
3740
internal class AnalysisUnit : ISet<AnalysisUnit> {

Nodejs/Product/Analysis/Analysis/JsAnalyzer.cs

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -143,15 +143,12 @@ public IAnalyzable AddPackageJson(string filePath, string entryPoint, List<strin
143143

144144
tree.DefaultPackage = entryPoint;
145145

146-
var requireAnalysisUnits = new List<RequireAnalysisUnit>();
146+
ProjectEntry projectEntry = null;
147147
if (dependencies != null) {
148-
var projectEntry = new ProjectEntry(this, filePath, null);
149-
requireAnalysisUnits.AddRange(dependencies.Select(
150-
dependency => { return new RequireAnalysisUnit(tree, Modules, projectEntry, dependency);
151-
}));
148+
projectEntry = new ProjectEntry(this, filePath, null);
152149
}
153150

154-
return new TreeUpdateAnalysis(tree, requireAnalysisUnits);
151+
return new TreeUpdateAnalysis(tree, dependencies, projectEntry, Modules);
155152
}
156153

157154
/// <summary>
@@ -162,22 +159,33 @@ public IAnalyzable AddPackageJson(string filePath, string entryPoint, List<strin
162159
[Serializable]
163160
internal class TreeUpdateAnalysis : IAnalyzable {
164161
private readonly ModuleTree _tree;
165-
private readonly IEnumerable<RequireAnalysisUnit> _requireAnalysisUnits;
162+
private readonly IEnumerable<string> _dependencies;
163+
private readonly ProjectEntry _projectEntry;
164+
private readonly ModuleTable _modules;
166165

167-
public TreeUpdateAnalysis(ModuleTree tree, IEnumerable<RequireAnalysisUnit> requireAnalysisUnits = null) {
166+
public TreeUpdateAnalysis(ModuleTree tree, IEnumerable<string> dependencies = null, ProjectEntry projectEntry = null, ModuleTable modules = null) {
168167
_tree = tree;
169-
_requireAnalysisUnits = requireAnalysisUnits;
168+
_dependencies = dependencies;
169+
_projectEntry = projectEntry;
170+
_modules = modules;
170171
}
171172

172173
public void Analyze(CancellationToken cancel) {
173174
if (_tree != null) {
174175
_tree.EnqueueDependents();
175176
}
176-
if (_requireAnalysisUnits != null) {
177-
foreach (var unit in _requireAnalysisUnits) {
177+
178+
if (_dependencies != null) {
179+
var requireAnalysisUnits = new List<RequireAnalysisUnit>();
180+
requireAnalysisUnits.AddRange(_dependencies.Select(
181+
dependency => {
182+
return new RequireAnalysisUnit(_tree, _modules, _projectEntry, dependency);
183+
}));
184+
185+
foreach (var unit in requireAnalysisUnits) {
178186
unit.AnalyzeWorker(null, cancel);
179187
}
180-
}
188+
}
181189
}
182190
}
183191

0 commit comments

Comments
 (0)