Skip to content

Switch System.IO usage with Microsoft.IO usage to reduce string allocations during scanning directory (and some other path manipulation too.)  #6075

@arunchndr

Description

@arunchndr

Child of #6034

CPS switch is here - https://devdiv.visualstudio.com/DevDiv/_git/CPS?path=%2Fsrc%2FMicrosoft.VisualStudio.ProjectSystem%2FUtilities%2FPathHelper.cs&version=GBmain&line=22&lineEnd=23&lineStartColumn=1&lineEndColumn=1&lineStyle=plain&_a=contents

Highlights of the switch

  • The assembly Microsoft.IO.Redist.dll is 118KB in size and loaded in CPS based projects
  • Fixes globalization issues in CPU based projects (Eg: Previously could not open projects in a path containing "%C3%A7" or \wsl$)
  • It has memory and cpu performance benefits over System.IO and used in CPS PathHelper.
    • Solution load numbers below show 10-12% load time improvements in both cold and warm load scenarios.
    • API benchmarks show marked improvements of 2-3 times less CPU per API call and a big gain in the memory saved per API call.
      • The API benchmarks can also be used as data to propose wider usage of the Microsoft.IO assembly to replace System.IO across the org
      • Disclaimer: Scale tests may not see a marked improvement atleast in this PR since the benchmarks show no Gen 1 or Gen 2 impact before or after with memory reclaimed in Gen 0 GC. It is intended to relieve the Gen 0 GC pressure
VS build Solution Cold Load(First load in ms) Solution Warm Load(Second Load in ms)
Before master.30209.217 7878 7810
After master.30209.218 7236 6886
Method Mean Error StdDev Gen 0 Allocated
SystemIOMakeRelative (Short paths) 2,613.1 ns 23.79 ns 21.09 ns 0.6180 2608 B
MicrosoftIOMakeRelative (Short paths) 764.4 ns 2.41 ns 2.01 ns 0.0210 88 B
SystemIOMakeRelative (Long paths) 4,395.9 ns 19.68 ns 18.41 ns 1.4801 6219 B
MicrosoftIOMakeRelative (Long paths) 1,014.3 ns 2.98 ns 2.79 ns 0.0496 209 B
Method Mean Error StdDev Gen 0 Allocated
SystemIOSamePath (2 Short paths) 976.82 ns 19.226 ns 27.573 ns 0.1488 626 B
MicrosoftIOSamePath (2 Short paths) 537.74 ns 10.348 ns 9.680 ns 0.0134 56 B
SystemIOSamePath (Short and long paths) 48.93 ns 0.975 ns 1.855 ns - -
MicrosoftIOSamePath (Short and long paths) 54.19 ns 0.994 ns 0.881 ns - -
SystemIOSamePath (Long and short paths) 49.50 ns 0.813 ns 0.760 ns - -
MicrosoftIOSamePath (Long and short paths) 55.68 ns 1.134 ns 1.061 ns - -
SystemIOSamePath (2 Long paths) 1,903.02 ns 6.298 ns 7.001 ns 0.2632 1107 B
MicrosoftIOSamePath (2 Long paths) 687.57 ns 6.361 ns 5.639 ns 0.0229 96 B
Method Mean Error StdDev Gen 0 Allocated
SystemIOMakeRooted (Short paths) 508.2 ns 10.22 ns 12.55 ns 0.0839 353 B
MicrosoftIOMakeRooted (Short paths) 353.3 ns 1.33 ns 1.24 ns 0.0095 40 B
SystemIOMakeRooted (Long paths) 1,132.1 ns 4.14 ns 3.46 ns 0.1411 594 B
MicrosoftIOMakeRooted (Long paths) 533.7 ns 2.37 ns 2.22 ns 0.0095 40 B
Method Mean Error StdDev Median Gen 0 Allocated
SystemIOChangeFileName (Long path with filename) 2,949.0 ns 67.68 ns 194.19 ns 2,930.4 ns 0.7401 3105 B
MicrosoftIOChangeFileName (Long path with filename) 762.8 ns 15.10 ns 15.51 ns 763.0 ns 0.0668 281 B
SystemIOChangeFileName (Long with directory\filename) 2,841.2 ns 54.62 ns 105.23 ns 2,830.4 ns 0.7477 3145 B
MicrosoftIOChangeFileName (Long with directory\filename) 776.3 ns 13.98 ns 31.83 ns 771.0 ns 0.0706 297 B
SystemIOChangeFileName (Short path with filename) 1,123.9 ns 22.55 ns 51.80 ns 1,104.3 ns 0.2632 1107 B
MicrosoftIOChangeFileName (Long path with filename) 467.1 ns 9.29 ns 17.90 ns 462.9 ns 0.0210 88 B
SystemIOChangeFileName (Long path with directory\filename) 1,215.4 ns 24.04 ns 39.50 ns 1,200.6 ns 0.2747 1155 B
MicrosoftIOChangeFileName (Long path with directory\filename) 488.5 ns 9.03 ns 11.42 ns 484.0 ns 0.0248 104 B
Method Mean Error StdDev Gen 0 Allocated
SystemIOCombine (Short paths) 272.9 ns 4.23 ns 3.31 ns 0.0153 64 B
MicrosoftIOCombine (Short paths) 102.9 ns 2.12 ns 2.09 ns 0.0153 64 B
SystemIOCombine (Long paths) 407.1 ns 2.45 ns 2.05 ns 0.0439 185 B
MicrosoftIOCombine (Long paths) 118.6 ns 2.35 ns 6.15 ns 0.0439 185 B

Metadata

Metadata

Assignees

Labels

Area: PerformancePriority:1Work that is critical for the release, but we could probably ship withouttriaged

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions