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

Remove the lamdba allocation during TypeRegistry`1.TryGetValue (which… #121

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ndrwrbgs
Copy link

@ndrwrbgs ndrwrbgs commented Apr 1, 2019

… is called indirectly by Template.Render())

.Where(i => i.IsAssignableFrom(key)) is using key which is captured from the surrounding closure. Therefore, the runtime allocates a new object to capture the Func<Type, bool> paired with it's required key input (rather than if there were, say, a WhereWithState<TSource, TState, TResult>(TSource, TState) method).

Since this is called by Template.Render() it adds unnecessary overhead we can remove without changes to the runtime by expanding the LINQ statement into a foreach loop.

@ndrwrbgs
Copy link
Author

ndrwrbgs commented Apr 1, 2019

The travis-ci build seems to have been failed for unrelated reasons, the actual test run passed

Total tests: 610. Passed: 606. Failed: 0. Skipped: 4.
Test Run Successful.
Test execution time: 3.2077 Seconds
The command "dotnet test Antlr4.Test.StringTemplate -f netcoreapp2.0" exited with 0.

Copy link
Member

@sharwell sharwell left a comment

Choose a reason for hiding this comment

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

Can we keep the current form, and avoid capturing the parameter on the fast path by moving the slow path code to TryGetValueSlow? If you aren't familiar with this pattern let me know and I can write it out when I'm at a computer tomorrow.

@ndrwrbgs
Copy link
Author

ndrwrbgs commented Apr 2, 2019

I don't think it does the allocariok unless this code is hit, unless I misunderstand something grave. And if this code is being hit then it'd be hit in another method if moved anyway, right?

I know it shouldn't be hit frequently given there's a cache but why not avoid the allocation even on cache miss? :)

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.

None yet

2 participants