Community.VisualStudio.Toolkit icon indicating copy to clipboard operation
Community.VisualStudio.Toolkit copied to clipboard

fetching projects and references is horribly slow

Open AdmiralSnyder opened this issue 2 years ago • 5 comments

I have a solution with 60 projects. when fetching the references using this code:

            var projects = await VS.Solutions.GetAllProjectsAsync();
            foreach (var project in projects) 
            {
                foreach (var reference in project.References)
                {
                    // my code here
                }
            }

this operation is unbearingly slow (almost 120 seconds for these 60 projects). is this the expected performance or maybe only an issue with the debug version? (if so, why is it that much slower?) thanks, Alex

AdmiralSnyder avatar Feb 04 '22 02:02 AdmiralSnyder

What sort of references (assembly, project or shared project) do those projects contain? And how many references are there in total?

I have a sample solution with about 400 projects, where each project references another project, so there are about 400 references (but only project references - there are no assembly references). It only takes a fraction of a second to iterate through them, so it definitely shouldn't be taking anywhere near the amount of time that you are seeing.

reduckted avatar Feb 04 '22 10:02 reduckted

with external references there's about 1.5 k references alltogether, lots of them are duplicated though.

AdmiralSnyder avatar Feb 04 '22 11:02 AdmiralSnyder

okay, i switched over to directly using DTE and VSLangProj which wasn't much faster, BUT i was able to use Parallel.ForEach and thus could reduce the time from 120 seconds to about 3 seconds - which is perfectly fine.

maybe some of the "throw when not on UI thread" restrictions should be removed, in the community toolkit.

@reduckted

AdmiralSnyder avatar Mar 06 '22 11:03 AdmiralSnyder

Perhaps we can use Parallel.ForEach in the toolkit too. The DTE and VSLanProj is UI threaded so that shouldn't have made any difference since a lot of marshalling would take place under the hood.

madskristensen avatar Mar 07 '22 17:03 madskristensen

@AdmiralSnyder Are you able to share the repository/solution that's slow, or is it private? Do you know of any open source repositories that have the same performance problem when getting references?

reduckted avatar Mar 08 '22 10:03 reduckted