dotnet/runtime

Improve File.Move performance

Open

#65,092 创建于 2022年2月9日

在 GitHub 查看
 (9 评论) (2 反应) (0 负责人)C# (5,445 fork)batch import
area-System.IOhelp wantedtenet-performance

仓库指标

Star
 (17,886 star)
PR 合并指标
 (平均合并 12天 11小时) (30 天内合并 661 个 PR)

描述

Similarly to what I did in https://github.com/dotnet/runtime/pull/63675 for Directory.Move there is most likely no need to perform a check whether source file exists in https://github.com/dotnet/runtime/blob/71393d07bc2f8a388dd2e06726757eaf11e3307c/src/libraries/System.Private.CoreLib/src/System/IO/File.cs#L417

The native sys-call that is called by FileSystem.MoveFile is most likely going to fail in such situations. We should just handle the FileSystem.MoveFile failure and map it to the same (existing) exception on both Windows and Unix.

The following condition can most likely avoid the check as well:

https://github.com/dotnet/runtime/blob/71393d07bc2f8a388dd2e06726757eaf11e3307c/src/libraries/System.Private.CoreLib/src/System/IO/FileSystem.Unix.cs#L225-L229

(we could check if the source file is the same file/drive as destination only after we verify that destination exists. In cases where destination does not exists there is no need of doing that)

While working on this it would be nice to unify File.Move and FileInfo.MoveTo and fix https://github.com/dotnet/runtime/issues/35122

The contributor who is willing to work on this issue needs to contribute File.Move benchmarks to the https://github.com/dotnet/performance repository. The File benchmarks can be found here. Here you can find docs that explain how to run the benchmarks against local build of dotnet/runtime.

贡献者指南