-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Remove bunch of allocations caused by static arrays by favoring ReadOnlySpan<T> #9230
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dotnet-policy-service
bot
added
PR
metadata: Label to tag PRs, to facilitate with triage
Community Contribution
A label for all community Contributions
labels
Jun 7, 2024
h3xds1nz
force-pushed
the
remove-static-arrays-allocs
branch
from
June 7, 2024 18:23
f684b2b
to
3fc9475
Compare
miloush
reviewed
Jun 8, 2024
.../src/PresentationBuildTasks/Microsoft/Build/Tasks/Windows/GenerateTemporaryTargetAssembly.cs
Outdated
Show resolved
Hide resolved
I had to remove the optimization in |
/azp run |
Azure Pipelines successfully started running 1 pipeline(s). |
This was referenced Jul 5, 2024
anjali-wpf
approved these changes
Jul 22, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your contribution.
Thanks @anjali-wpf for including it. |
bgrainger
reviewed
Jul 22, 2024
...crosoft.DotNet.Wpf/src/PresentationCore/MS/internal/Ink/InkSerializedFormat/InkSerializer.cs
Show resolved
Hide resolved
# for free
to subscribe to this conversation on GitHub.
Already have an account?
#.
Labels
Community Contribution
A label for all community Contributions
PR
metadata: Label to tag PRs, to facilitate with triage
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Fixes unnecessary allocations on
static readonly
arrays by refactoring them asReadOnlySpans<T>
of primitive types.This under the hood allows references in runtime to the data directly as stored in the mapped file, not requiring any runtime allocs. See RuntimeHelpers.CreateSpan<T> intrinsic for more info. In most cases the value is then inlined directly into the method, saving memory references as well.
In other cases, such as the Geometry classes, it allows us to reference data directly without any pinning (
fixed
is then merely used to retrieve the pointer that's passed to the unsafe method.This also removes some unoptimized foreaches as replacement for
IndexOf
/Contains
(guess that's coming from very early in the days).In the end, it also removes inefficient
foreach
andIndexOf
replacements forContains
methods withROS<char>.Contains(value)
.Customer Impact
Improved performance, decreased allocations.
Regression
None.
Testing
Build and standard use. Should be easy to CR.
Risk
Low.
Microsoft Reviewers: Open in CodeFlow