I can live with only the files in the workspace. Now when I tried again I got 10 seconds for 398 files. Thats 26 ms per file. That's a huge amount of time. In that time I you could render a whole frame for a modern 3D game! After restarting Visual Studio this went down to about 2 seconds.
Now This didn't make sense, so I debugged Visual Studio and checked what was taking time. You seems to call Item(x) on something. Every call seems to enumerato all documents and put them in a list that is then indexed!
I created a testcase with Visual Basic script that does the same thing that you do and if I call Item(x) three times per file it seems to take about the same amount of time that your dialog take. There is a GetEnumerator() available on DTE.Documents property. Using this (foreach in VB macro) I got the following times:
Number of documents: 398
Time for Item(): 1218.75 ms
Time for IEnumerator(): 46.875 ms
My VB skills are a bit lacking but the code:
Sub Macro_CountDocuments()
Dim nObjects = 0
nObjects = DTE.Documents.Count
Dim ItemTimerStart As DateTime
Dim ItemTimerEnd As DateTime
Dim EnumeratorTimerStart As DateTime
Dim EnumeratorTimerEnd As DateTime
If 1 Then
ItemTimerStart = DateTime.Now
For i = 1 To nObjects
Dim Docu = DTE.Documents.Item(i)
Dim Docu0 = DTE.Documents.Item(i)
Dim Docu1 = DTE.Documents.Item(i)
Next
ItemTimerEnd = DateTime.Now
End If
If 1 Then
EnumeratorTimerStart = DateTime.Now
For Each Docum In DTE.Documents
Dim Docu = Docum
Dim Docu0 = Docum
Dim Docu1 = Docum
Next
EnumeratorTimerEnd = DateTime.Now
End If
OutputWindowLog("Number of documents: " + nObjects.ToString() + vbCrLf)
Dim FileTimeStart = ItemTimerStart.ToFileTime()
Dim FileTimeEnd = ItemTimerEnd.ToFileTime()
OutputWindowLog("Time for Item(): " + ((FileTimeEnd - FileTimeStart) / 10000.0).ToString() + " ms" + vbCrLf)
FileTimeStart = EnumeratorTimerStart.ToFileTime()
FileTimeEnd = EnumeratorTimerEnd.ToFileTime()
OutputWindowLog("Time for IEnumerator(): " + ((FileTimeEnd - FileTimeStart) / 10000.0).ToString() + " ms" + vbCrLf)
End Sub