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

Fix allocation on tickables #279

Merged
merged 6 commits into from
Jul 10, 2021
Merged

Fix allocation on tickables #279

merged 6 commits into from
Jul 10, 2021

Conversation

adarapata
Copy link
Collaborator

When using Tickable, GC Allocation of 40 bytes per frame was occurring.
IEnumerable<T>.GetEnumerator() causes an implicit cast, I think.

To solve this problem, I modified the LoopItem to explicitly hold the List inside.

I'd like you to see if it looks OK. 🙏

@vercel
Copy link

vercel bot commented Jul 10, 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/CTKEgrG73cUsuiH1fJsgipwsdqmG
✅ Preview: https://vcontainer-git-fork-adarapata-fixallocationontickables-hadashia.vercel.app

@adarapata adarapata marked this pull request as ready for review July 10, 2021 08:55
readonly EntryPointExceptionHandler exceptionHandler;
bool disposed;

public FixedTickableLoopItem(
IEnumerable<IFixedTickable> entries,
EntryPointExceptionHandler exceptionHandler)
{
this.entries = entries;
this.entries = entries.ToList();
Copy link
Owner

@hadashiA hadashiA Jul 10, 2021

Choose a reason for hiding this comment

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

I think it would be better if ToList() was removed.
( It is not clearly that no copying will occur

This class is internal and has no use case other than being passed an IReadOnlyList<T>.
In this case, why not keep IReadOnlyList<T> as an argument, and use for and [] operator instead of foreach ?
( for ... statement is exactly the same as the implementation of List<>.GetEnumerator. )

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

In this case, why not keep IReadOnlyList as an argument, and use for and [] operator instead of foreach ?

I like that!

Assert.That(() =>
{
tickableLoopItem.MoveNext();
}, Is.Not.AllocatingGCMemory());
Copy link
Owner

Choose a reason for hiding this comment

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

👍

@adarapata
Copy link
Collaborator Author

Thanks for the review!
I've responded.

@hadashiA hadashiA merged commit 36089e6 into hadashiA:master Jul 10, 2021
@adarapata adarapata deleted the fix_allocation_on_tickables branch July 10, 2021 09:42
@hadashiA
Copy link
Owner

This makes sense. Thanks!

@hadashiA hadashiA mentioned this pull request Jul 21, 2021
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