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

More allocations when using LinqGen than normal Linq. #4

Closed
octoberU opened this issue Jan 17, 2023 · 3 comments
Closed

More allocations when using LinqGen than normal Linq. #4

octoberU opened this issue Jan 17, 2023 · 3 comments
Assignees
Labels
enhancement New feature or request

Comments

@octoberU
Copy link

Did some testing on a hobby project to see how LinqGen would perform but ended up with slower/more memory heavy results.

Version used: v0.2.1

Default Linq query.

value
.OrderBy(x => x.timeMs)
.ThenBy(x => x.behavior)
.ThenBy(x => x.handType)
.ToArray();

LinqGen query.

value
.Gen()
.OrderBy(new TargetCueSelectors.SelectCueTimeMs())
.ThenBy(new TargetCueSelectors.SelectCueBehavior())
.ThenBy(new TargetCueSelectors.SelectCueHandType())
.ToArray();

Default Linq
Unity_stBv7OjpZ2
LinqGen
Unity_PeVF1SL9zb

Is there something I'm doing wrong? The only thing that stands out to me right now is the multiple "ThenBy"s.

@cathei cathei added the enhancement New feature or request label Jan 17, 2023
@cathei cathei self-assigned this Jan 17, 2023
@cathei
Copy link
Owner

cathei commented Jan 17, 2023

Thanks for reporting this. This is very interesting. It seems like comparing int to null in generic comparer causes boxing allocation in Debug setting. If it's in Release setting this consider always false and boxing doesn't happen. The benchmarks are in Release setting so I haven't noticed this. I will update the code to avoid this allocation in Debug setting as well.

@octoberU
Copy link
Author

Thank you for the quick response, gonna give it another go with the next release once it comes out.

@cathei
Copy link
Owner

cathei commented Jan 20, 2023

It has been included in v0.2.2.
Allocation won't happen in Debug build and editor.
For performance profiling, please use Release mode without deep profiling in the Editor to get correct result.

@cathei cathei closed this as completed Jan 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants