Large custom MPF projects slow to load? Solution here!
-
Wednesday, November 26, 2008 7:18 PM
For our projects with 2000-3000 files, this results in a 30:1 improvement in project load times.
1. In ProjectNode.Reload(), move ProcessFolders() before ProcessFiles().
2. In ProjectNode.ProcessFiles(), change:foreach (MSBuild.BuildItem item in projectFiles)
toforeach (MSBuild.BuildItem item in projectFiles.Cast<MSBuild.BuildItem>().OrderByDescending(i=>i.FinalItemSpec ?? i.Name))
3. Add the following member variables to your class that derives from ProjectNode:1 // serious optimization for Reloads of large projects: 2 Dictionary<string, HierarchyNode> _folders; 3 bool _reloading; 4
4. Override ProjectNode.Reload() in your custom ProjectNode class. Change the call to base.Reload() to this:1 _reloading = true; 2 _folders = new Dictionary<string, HierarchyNode>( StringComparer.OrdinalIgnoreCase ); 3 4 try 5 { 6 base.Reload(); 7 } 8 finally 9 { 10 _reloading = false; 11 _folders = null; 12 } 13
5. Override ProjectNode.CreateFolderNodes(string path) in your custom ProjectNode class as follows:1 public override HierarchyNode CreateFolderNodes( string path ) 2 { 3 HierarchyNode node; 4 5 if ( _reloading ) 6 { 7 if ( _folders.TryGetValue( path, out node ) ) 8 return node; 9 } 10 11 node = base.CreateFolderNodes( path ); 12 if ( _reloading ) 13 _folders[path] = node; 14 15 return node; 16 } 17
All Replies
-
Saturday, February 25, 2012 7:35 PMI am a beginner with building packages. This looks like what I need. I am adding possibly thousands of projectitems to the project at once. What interfaces would I be using to be able to use these optimizations?
-
Saturday, February 25, 2012 11:46 PMModerator
This post is about people providing custom project systems, it wouldn't do anything if you were interacting with a project system. I don't know if there is an optimal way to add 'thousands of projectitems', that likely isn't a mainline scenario that the APIs were designed for.
Ryan

