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 .NET 9 #97

Merged
merged 2 commits into from
Dec 5, 2024

Conversation

GerardSmit
Copy link
Contributor

@GerardSmit GerardSmit commented Dec 4, 2024

In .NET 9 it's now possible to get a dictionary value with a ReadOnlySpan<char>.

We're using a dictionary with lookup in the following places:

  1. ZipArchiveFileSystem - Checking if the parent dictionary exists
  2. MemoryFileSystem - When getting the node, we split the path and enumerate through it

In this PR I changed these lookups to a lookup with ReadOnlySpan<char>, so we're allocating less memory.

Project changes

  • Added .NET 9 as target framework
  • Changed the version to 9.0.100 in global.json
  • Added PackageReference to System.Memory for .NET Standard and .NET Framework
  • Changed lang version to 13, so we can use ref structs.

New API's

  • UPathExtensions.GetDirectoryAsSpan(this UPath path) - Gets the dictionary as a span
  • UPathExtensions.SpanSplit(this UPath path) - Returns an enumerator which returns the sections of the path as span

@GerardSmit GerardSmit changed the title Improve allocations in .NET 9 Reduce allocations in .NET 9 Dec 4, 2024
@xoofx xoofx merged commit eb0ebb4 into xoofx:main Dec 5, 2024
2 checks passed
@xoofx
Copy link
Owner

xoofx commented Dec 5, 2024

Nice, thanks!

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

Successfully merging this pull request may close these issues.

2 participants