Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Add custom file copy logics for template files #9369

Merged
merged 2 commits into from
Nov 2, 2023

Conversation

filzrev
Copy link
Contributor

@filzrev filzrev commented Nov 2, 2023

This PR intended to resolve #9183 issue.

When running docfx build command with multiple times.
There are unnecessaries operations that overwrite identical files.

This PR add features to skip this operations when template files is not changed.
It's required when using something like dotnet watch scenarios.

What's included in this PR

  • Add custom template file copy logics for FileStream.
    • Skip file copy operation when following conditions met.
      1. Output file is already exists.
      2. Files length are same.
      3. Files LastWriteTime is same.
    • If above condition is not met. Use File::Copy API to preserve original LastWriteTime.
  • Add PreallocationSize settings for FileStream

Benchmark Results
I've tested on samples/seed project and measuring TemplateProcessor::CopyTemplateResources elapsed times.

  1. When it can skip file copy. it's running 10x faster, (e.g. 86.7 [ms] -> 8.0 [ms])
  2. When it needs to copy new file and overwrite files.
    It's running slightly slower about 10% (e.g. 86.7 [ms] -> 96.4 [ms])
    I thought it's because of following reasons
    • File.Copy API requires additional operations (e.g. file's attribute copy)
    • It need to open file twice (Open FileStream. then call File::Copy)

Copy link

codecov bot commented Nov 2, 2023

Codecov Report

Attention: 14 lines in your changes are missing coverage. Please review.

Files Coverage Δ
...ocfx.Build/TemplateProcessors/TemplateProcessor.cs 64.13% <46.15%> (-14.45%) ⬇️

📢 Thoughts on this report? Let us know!.

@filzrev filzrev force-pushed the chore-add-fastcopy-path-for-filestream branch from 0658a9e to eaa7a45 Compare November 2, 2023 10:13
@KalleOlaviNiemitalo
Copy link

KalleOlaviNiemitalo commented Nov 2, 2023

Starting from .NET 7.0, File.Copy can make a copy-on-write clone on some file systems, consuming less time and disk space than a full copy of the file content. That is thus a good change even if the copy cannot be skipped entirely.

Copy link
Contributor

@yufeih yufeih left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Look good. Thank you @filzrev !

@yufeih yufeih added the new-feature Makes the pull request to appear in "New Features" section of the next release note label Nov 2, 2023
@yufeih yufeih merged commit 57d0849 into dotnet:main Nov 2, 2023
7 checks passed
p-kostov pushed a commit to ErpNetDocs/docfx that referenced this pull request Jun 28, 2024
@filzrev filzrev deleted the chore-add-fastcopy-path-for-filestream branch July 12, 2024 10:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new-feature Makes the pull request to appear in "New Features" section of the next release note
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature Request] Support Copy if newer feature to copy resource files to destination
3 participants