Skip to content

Reduce allocations and improve throughput - #619

Merged
tannergooding merged 10 commits into
dotnet:mainfrom
tannergooding:main
Aug 13, 2025
Merged

Reduce allocations and improve throughput#619
tannergooding merged 10 commits into
dotnet:mainfrom
tannergooding:main

Conversation

@tannergooding

Copy link
Copy Markdown
Member

This targets a few different hot spots found in the profiler.

@tannergooding
tannergooding merged commit 1f2fff4 into dotnet:main Aug 13, 2025
13 checks passed
{
if (_factory is Func<T> factory)
{
_value = factory();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

If I am not mistaken, without setting _factory to null, the _value will be recalculated on every access to Value property.

Suggested change:

    if (_factory is Func<T> factory)
    {
        _value = factory();
+       _factory = null;
    }

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Ah yeah, I forgot to add that line -.-

PRs are welcome, otherwise I'll put one up later this evening.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants