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 TransformArrayInitializers #2731

Merged

Conversation

ElektroKill
Copy link
Contributor

Link to issue(s) this covers
N/A

Problem

The TransformArrayInitializers allocates a lot of unnecessary arrays.

Solution

DecodeArrayInitializer - Instead of relying on the Add method of a list to expand the underlying array when necessary, the code now allocates a big enough array to fit all the elements removing the need for the Add method to expand the array several times.

BlockFromInitializer now reuses a single instance of List instead of reallocating a new one every time and clears it when necessary. The same pre-allocation approach mentioned above has been implemented here too.

DecodeArrayInitializer - Instead of relying on the Add method of a list to expand the underlying array when necessary, the code now allocates a big enough array to fit all the elements removing the need for the Add method to expand the array several times.

BlockFromInitializer now reuses a single instance of List<ILInstruction> instead of reallocating a new one every time and clears it when necessary. The same pre-allocation approach mentioned above has been implemented here too.
@dgrunwald dgrunwald merged commit 06039f2 into icsharpcode:master Jul 12, 2022
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