-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Use next sibling in SyntaxNode.GetChildPosition() if available #66876
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
6d82cde
Use next sibling in SyntaxNode.GetChildPosition() if available
cston 86786a2
Update test
cston 4bea78e
Add test
cston 050f570
Fix build
cston 14c639e
Verify child positions
cston 95880f0
Add verification without cache
cston 8f18f02
Update comments
cston 9e8e9ce
Add comment
cston a98cb9a
Add tests with trailing separator
cston bff2282
Remove comment
cston 528a2a8
Add comment
cston 80f0ab8
Use GetCachedSlot()
cston 724aecd
Call GetCachedSlot(index)
cston c187e3d
Update tests: add comments; increase iterations
cston File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Use GetCachedSlot()
- Loading branch information
commit 80f0ab88cf6303258efc6225e60b67c365f8b93f
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It feels like the correlation between cache checks performed by
GetChildPositionFromEndand cache checks performed here would be more obvious if we were usingGetCachedSlothelper rather than working with_childrenon the low level. Also, could we instead adjust implementation ofGetChildPositionto perform the same cache tests for the following child? Then all the logic would be in one place, and, perhaps, we wouldn't need to provide a generalGetChildPositionFromEndhelper, since it looks like we really want to handle just 3 specific situations.It looks like the optimization targets very limited set of scenarios. For example, when we are far from the end and the next sibling isn't cached, but the one after the next is cached, we won't take advantage of that cached sibling. Would it make sense to generalize the optimization. For example, even if nothing is cached, it still might be faster to calculate from end simply because the item is closer to the end than to the front. Similarly, we could make decision based on the proximity of the first cached item going backwards vs. going forward. Perhaps we could maintain a bitmap of cached items to speed-up the process of finding closest cached items. #Closed
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the optimization specifically targets the scenario where the first iteration through the child list is in reverse, so the previous siblings are not in the cache. That's the one scenario we have currently where there is a perf issue. The optimization here is simply to calculate the position based on the offset from the immediately following sibling when that sibling is in the cache; otherwise, we use the existing approach.
We should limit the change here to fixing this one scenario, to avoid perf regressions in other cases. If additional scenarios arise, we can consider further optimizations.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GetChildPosition()doesn't know about separated lists (where the separator is not in the cache) so it would be surprising for that method to skip over some siblings when determining whether using the following sibling is a better choice.I added
GetChildPositionFromEnd()next toGetChildPostion()so the two loops were together. And I think we'd still need the cases that are handled inGetChildPositionFromEnd(), even if the methods were combined. I'll keep the two methods separate so that both implementations are clear.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated.