Skip to content
New issue

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

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

Already on GitHub? # to your account

Reduce DG Spec Write Frequency #6259

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from

Conversation

nkolev92
Copy link
Member

@nkolev92 nkolev92 commented Feb 6, 2025

Bug

Fixes: NuGet/Home#14135

Description

When a restore is completed successfully, it has dirty checks for the assets file and the nuget.g.props and nuget.g.targets.
This is important because these 3 trigger a DTB.
However, dgspec.json does not have a dirty check and that leads to a dgspec write when someone runs something as simple as rebuild in VS.

The "dgspec.json" content is what's used for the no-op hash, so using that value to determine whether to write should be good enough of heuristic.

PR Checklist

  • Meaningful title, helpful description and a linked NuGet/Home issue
  • Added tests
  • Link to an issue or pull request to update docs if this PR changes settings, environment variables, new feature, etc.

@microsoft-github-policy-service microsoft-github-policy-service bot added the Status:No recent activity PRs that have not had any recent activity and will be closed if the label is not removed label Feb 16, 2025
@nkolev92 nkolev92 force-pushed the dev-nkolev92-reduceDgSpecWriteFrequency branch from 0c548cb to 4e3bfac Compare February 19, 2025 23:23
@microsoft-github-policy-service microsoft-github-policy-service bot removed the Status:No recent activity PRs that have not had any recent activity and will be closed if the label is not removed label Feb 19, 2025
@nkolev92 nkolev92 marked this pull request as ready for review February 24, 2025 19:20
@nkolev92 nkolev92 requested a review from a team as a code owner February 24, 2025 19:20
Copy link
Contributor

@donnie-msft donnie-msft left a comment

Choose a reason for hiding this comment

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

Look forward to seeing the impact of this change!
Just left a few nits...

@@ -412,11 +415,13 @@ private void InitializeTelemetry(TelemetryActivity telemetry, int httpSourcesCou
cacheFile,
_request.Project.RestoreMetadata.CacheFilePath,
_request.ProjectStyle,
restoreTime.Elapsed), cacheFile);
restoreTime.Elapsed), noOpCacheFileEvaluation, cacheFile);
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: newlines for these parameters

public async Task RestoreResult_Commit_WithExistingDGSpecAndDidDGHashChange_WritesDependencyGraphSpec(bool didDGHashChange)
{
// Arrange
using (var td = TestDirectory.Create())
Copy link
Contributor

Choose a reason for hiding this comment

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

[Theory]
[InlineData(true)]
[InlineData(false)]
public async Task RestoreResult_Commit_WithExistingDGSpecAndDidDGHashChange_WritesDependencyGraphSpec(bool didDGHashChange)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: It'd be good to get away from repeating test class names in test method names.
non-nit: The criteria isn't clear here. I read the assertions as it should only write when the DGHash changed, because it already existed. Can the test name be clearer?

Suggested change
public async Task RestoreResult_Commit_WithExistingDGSpecAndDidDGHashChange_WritesDependencyGraphSpec(bool didDGHashChange)
public async Task CommitAsync_WithExistingDGSpec_OnlyWritesWhen_DidDGHashChangeIsTrue(bool didDGHashChange)

var path = Path.Combine(td, "project.assets.json");
var cachePath = Path.Combine(td, "project.csproj.nuget.cache");
var dgSpecPath = Path.Combine(td, "project1.nuget.g.dgspec.json");
File.WriteAllText(dgSpecPath, "{}");
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm guessing we don't have much choice in implementing this test without writing to disk? I quickly checked ProjectTestHelpers in Test.Utility and didn't see a utility to avoid this write.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

NuGet restore writes dgspec too frequently
2 participants