perf(Completions): Reduce string allocations in CompletionContext string parsing - #2854
Conversation
|
Is there any effect on |
|
Hi @KalleOlaviNiemitalo! Thanks for the review. Additionally, I noticed the CI failed on some platforms. I am investigating the test failures locally and will push a fix shortly! |
I don't see why there would be a large number of those arrays.
Do you have the measurements? |
|
you're right, "large number" was an overstatement. it's 2 arrays per call. that said, I ran a BenchmarkDotNet comparison and the actual overhead from Split is bigger than I expected because it tokenizes the entire input string, not just the parts we need:
roughly 7-11x faster and 80-94% less memory per call. happy to include this benchmark in the PR if it helps. |
baronfel
left a comment
There was a problem hiding this comment.
This is a nice fix! Good spot that we were being pretty wasteful (though certainly very clear and understandable) here.
Description
This PR optimizes the
GetWordToCompleteparser by replacing chained.Split(' ')and LINQ allocations with zero-allocationIndexOfandLastIndexOfslice arithmetic.Testing
ParserTestsandCompletionTestsassert the logic doesn't break edge cases.net10.0.