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 #63

Merged
merged 1 commit into from
Sep 19, 2024
Merged

Reduce allocations #63

merged 1 commit into from
Sep 19, 2024

Conversation

jaredpar
Copy link
Owner

The structure of getting a PortableExecutableReference meant that we were essentially paying for byte[] twice. The first is generating the byte[] for the resource and then when that was passed to CreateFromImage it was converted to an ImmutableArray<byte> which means there is yet another byte[] allocation. To avoid this the code now just directly allocates the ImmutableArray<byte> and passes that to CreateFromImage.

This can save up to 45MB in certain cases I was looking at in the Roslyn tests.

The structure of getting a `PortableExecutableReference` meant that we
were essentially paying for `byte[]` twice. The first is generating the
`byte[]` for the resource and then when that was passed to
`CreateFromImage` it was converted to an `ImmutableArray<byte>` which
means there is yet another `byte[]` allocation. To avoid this the code
now just directly allocates the `ImmutableArray<byte>` and passes that
to `CreateFromImage`.

This can save up to 45MB in certain cases I was looking at in the Roslyn
tests.
@jaredpar jaredpar merged commit 66263ca into main Sep 19, 2024
1 check passed
@jaredpar jaredpar deleted the alloc branch September 19, 2024 16:57
jaredpar added a commit to dotnet/roslyn that referenced this pull request Sep 19, 2024
This updates the basic reference assemblies packages to a fix that removed a double allocation of `byte[]` when creating references

jaredpar/basic-reference-assemblies#63
jaredpar added a commit to dotnet/roslyn that referenced this pull request Sep 19, 2024
This updates the basic reference assemblies packages to a fix that removed a double allocation of `byte[]` when creating references

jaredpar/basic-reference-assemblies#63
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.

1 participant