dotnet / machinelearning

ML.NET is an open source and cross-platform machine learning framework for .NET.
https://dot.net/ml
MIT License
9.05k stars 1.88k forks source link

GetTempPath hot in some benchmarks in Microsoft.ML.PerformanceTests #7277

Open alexcovington opened 1 month ago

alexcovington commented 1 month ago

I have noticed that depending on the length of the temporary path, some benchmarks see a significant performance drop because of the need to convert from a Windows short name to a long name.

If I use the temporary directory path C:\tempdir\, the benchmark gives these performance results on my machine:

Microsoft.ML.PerformanceTests.exe --filter '*CreatePredictionEngine' --envVars TEMP:C:\tempdir TMP:C:\tempdir

| Method                 | Mean     | Error   | StdDev  | Extra Metric |
|----------------------- |---------:|--------:|--------:|-------------:|
| CreatePredictionEngine | 249.5 us | 4.80 us | 4.93 us |            - |

If I use a long temporary directory C:\Users\username\AppData\Local\Temp\ML.NET\A Very Very Long File Name That Will Be Converted To A Short Path\Temp (which has the short name C:\Users\username\AppData\Local\Temp\ML.NET\AVERYV~1\Temp), the benchmark shows significantly worse performance on the same machine:

 .\Microsoft.ML.PerformanceTests.exe --filter '*CreatePredictionEngine' --envVars TEMP:C:\Users\username\AppData\Local\Temp\ML.NET\AVERYV~1\Temp TMP:C:\Users\username\AppData\Local\Temp\ML.NET\AVERYV~1\Temp

| Method                 | Mean     | Error    | StdDev   | Extra Metric |
|----------------------- |---------:|---------:|---------:|-------------:|
| CreatePredictionEngine | 10.53 ms | 0.082 ms | 0.077 ms |            - |

Looking at this under PerfView, I see a lot of extra time spent here.

I'm wondering if it is possible to cache this lookup? It seems misleading for the benchmark performance to fluctuate so much because of the temporary directory path.