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

Optimize foreach performance #262

Merged
merged 1 commit into from
Jun 19, 2021
Merged

Optimize foreach performance #262

merged 1 commit into from
Jun 19, 2021

Conversation

hadashiA
Copy link
Owner

@hadashiA hadashiA commented Jun 15, 2021

Array<> and List<> foreach will be expanded into allocation-free code at compile time.
However, Interfaces such as Ilist<> and IReadOnlyList<> don't seem to do so. It seems that allocations occur because they go through the IEnumerator.

I preferred IReadOnlyList<>, but found that changing foreach to a for statement reduced the allocation.

Refs:
https://levelup.gitconnected.com/ilist-t-vs-list-t-performance-dad1688a374f

An example of container build test case

Before

screenshot-2021-06-19-124315

After

screenshot-2021-06-19-123156

@vercel
Copy link

vercel bot commented Jun 15, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/hadashia/vcontainer/4nY43pjJV8NBzFzxBEwMjtRoM3dD
✅ Preview: https://vcontainer-git-ku-optimize-foreach-hadashia.vercel.app

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