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

Reduce allocations in VirtualFileInfo.Name #12550

Closed
zivkan opened this issue Apr 23, 2023 · 0 comments · Fixed by NuGet/NuGet.Client#5141
Closed

Reduce allocations in VirtualFileInfo.Name #12550

zivkan opened this issue Apr 23, 2023 · 0 comments · Fixed by NuGet/NuGet.Client#5141
Assignees
Labels
Milestone

Comments

@zivkan
Copy link
Member

zivkan commented Apr 23, 2023

VisualFileInfo is an implementation of IFileInfo used with Microsoft.Extensions.FileSystemGlobbing. It's used when matching files in the package to files listed in the contentFiles section of package nuspec files.

The property is getting the filename from a path, but it does so with PhysicalPath.Split('/').LastOrDefault();. Both Split and LastOrDefault cause allocations, plus the result is not cached and debugging shows the same instance can have the Name getter called multiple times.

This code is used when generating the assets file when restoring a PackageReference project that uses a package that has contentFiles/* assets.

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

Successfully merging a pull request may close this issue.

2 participants