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

Autocomplete: Bring back completion synthesization from prior requests and retest all inflight requests #559

Merged
merged 18 commits into from
Aug 7, 2023

Conversation

philipp-spiess
Copy link
Contributor

@philipp-spiess philipp-spiess commented Aug 3, 2023

This PR brings back a completion cache that is able to synthesize results even if the request has changed. It's much simpler than the old request cache and only keeps a maximum of 50 completions around.

When the cache is queried, we compare the document position with all cached completions for the same file and if there's something salvageable, we synthesize a new completion base off of the previous one.

The data structures are kept much simpler now. Instead of having a map of multiple arrays of completions, we flattened the data structure to only be an array of completions. Inflight request logging was also changed from a per-file map to a flat set.

Todo

I noticed what appears to be a regression that I’m still investigating. Sometimes the last candidate response will not be the actual last completion that was visible. You can notice this happening at ~26sec in this video:

Screen.Recording.2023-08-03.at.15.11.40.mov

Test plan

Type a console.log statement, leafing only a tiny pause after one character. Observe that the response is going to be marked as CacheAfterRequestStarted:

Screenshot 2023-08-03 at 14 14 14

@philipp-spiess philipp-spiess requested a review from sqs August 3, 2023 13:13
@philipp-spiess philipp-spiess self-assigned this Aug 3, 2023
@philipp-spiess
Copy link
Contributor Author

philipp-spiess commented Aug 3, 2023

I noticed what appears to be a regression that I’m still investigating. Sometimes the last candidate response will not be the actual last completion that was visible. You can notice this happening at ~26sec in this video:

I think this happens because now, multiple completion requests can be merged into a new completion array but we do not keep track of which exact completion of the array was the last visible one. I think we'll have to add this because we only ever want this logic to trigger if the exact same completion is visible again. I know we need to store all of the returned items so the hover tooltip works, but for the comparison we only need to look at one.

Edit: This seems to work

Screen.Recording.2023-08-03.at.15.30.55.mov

@philipp-spiess philipp-spiess marked this pull request as ready for review August 3, 2023 13:53
@philipp-spiess philipp-spiess requested a review from a team August 3, 2023 13:53
@sqs sqs force-pushed the ps/autocomplete-synthesize-from-cache branch from c814b5d to 3267de2 Compare August 3, 2023 22:02
Copy link
Member

@sqs sqs left a comment

Choose a reason for hiding this comment

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

Thank you! I added some comments that IMO should be addressed before merging.

Take my input as that from a random dev out there--you make the final decision here.

I do worry about the network cache becoming too complex and bug-prone as it:

  1. Models a subset of document contents, document edit behavior, and editor view state.
  2. Interacts with the way that ghost text is and should be shown (ie the LastCandidate "cache"). (My concern here is eliminated if the Opt-out from the last candidate logic when a previously invisible ghost text would be used commit is reverted, as then the LastCandidate cache takes more of a primary/differentiated role then and there is less overlap.)

I also totally understand the value of cache entry synthesis from already in-flight requests that fortunately predicted the user's subsequent typing.

The // glitch (cac-slashslashspace-glitch.mp4 posted below) is an example of what I am worried we will be encountering a lot with the network cache. Maybe it is just that one issue and then it's good! I don't know.

I don't know the right solution or trade-off, and I trust you to make the call.

vscode/src/completions/cache/cache.ts Outdated Show resolved Hide resolved
vscode/src/completions/getInlineCompletions.ts Outdated Show resolved Hide resolved
vscode/src/completions/getInlineCompletions.test.ts Outdated Show resolved Hide resolved
vscode/src/completions/getInlineCompletions.test.ts Outdated Show resolved Hide resolved
@philipp-spiess
Copy link
Contributor Author

@sqs Thank you for the detailed feedback!

I’m now thinking that we can probably just reuse the "last candidate" logic here instead of using a fully blown cache like this. So when a previously in-flight request finishes and we do the "retest cache" logic, we can also pretend it is the last candidate and see if it would still apply.

@philipp-spiess philipp-spiess force-pushed the ps/autocomplete-synthesize-from-cache branch from 3267de2 to b30d537 Compare August 4, 2023 08:33
@philipp-spiess philipp-spiess marked this pull request as draft August 4, 2023 08:33
@philipp-spiess
Copy link
Contributor Author

Hm, not happy with this approach either:

  • The last candidate logic would need to be refactored since it also takes ranges and log IDs into account, something we don't have in the request manager
  • Reusing the last candidate logic and only comparing a newly resolved response against all inflight requests does not seem to be enough. While the tests pass and everything works as expected, the real world impact is not as noticeable (especially with the fast StarCoder 7b model I’m running - an exact timing like this does not occur often). So it seems like we also want to synthesis before we even start a request in case a prior request form the same line was already resolved. Something the previous CompletionCache approach supported.
    • I wonder now if this change is the actual culprit that caused the latency regression, the impact of this can be more than the ~10% of synthesized responses for inflight requests. Will try to check if I can find logs to see how often cache hits were used previously and how often they are now.
  • Supporting the forward-typing only case seems to be good enough though.
  • I have a hunch that we do need to run the post process logic before we reuse the completion to synthesise a new one. This is likely what's happening in Autocomplete: Bring back completion synthesization from prior requests and retest all inflight requests #559 (comment). Not quite sure how to do that yet, I want to avoid making the request manager aware of the post process step.

I'll need think about this a bit more (and also really start writing my reviews now 😐).

@philipp-spiess
Copy link
Contributor Author

philipp-spiess commented Aug 4, 2023

Memo to self: Check what happens if we return a completion result even though a new inline complete call was triggered.

Expectation: VS Code will disregard the completion (unless it matches the new prefix perhaps?)

Idea: If that's the case, we might return instead of cancelling all completion results and only completely rely on the "last candidate" logic. We just need to make sure these are not logged as being visible.

@philipp-spiess
Copy link
Contributor Author

Ohh this works great!

@philipp-spiess philipp-spiess marked this pull request as ready for review August 4, 2023 11:09
@philipp-spiess
Copy link
Contributor Author

philipp-spiess commented Aug 4, 2023

Todo

  • Add at least one test case to make sure we indeed yield aborted requests so that the last candidate logic can kick in.
  • Ensure that latencies are correctly logged now that we not always log events after they are emitted
    • It's best we create an extra callback after the data is post-processed to rule out any issues like this in the future

@philipp-spiess philipp-spiess force-pushed the ps/autocomplete-synthesize-from-cache branch 3 times, most recently from 48ad7b6 to 994c63f Compare August 7, 2023 11:55
@philipp-spiess philipp-spiess force-pushed the ps/autocomplete-synthesize-from-cache branch from 994c63f to 075f90a Compare August 7, 2023 12:16
@philipp-spiess philipp-spiess requested review from a team and removed request for a team August 7, 2023 13:05
…he completion to contain all characters from the replaced section
@philipp-spiess philipp-spiess merged commit c300cb3 into main Aug 7, 2023
9 checks passed
@philipp-spiess philipp-spiess deleted the ps/autocomplete-synthesize-from-cache branch August 7, 2023 13:34
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