-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Optimistic Next Edit Suggestions #222
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
base: main
Are you sure you want to change the base?
Optimistic Next Edit Suggestions #222
Conversation
|
hey @ulugbekna, i'd appreciate your [& other code owners] insight on this. There are some kinks to iron out, but in my testing, this massively improves the UX of NES. some points for discussion: Optimistic NES will multiply the number of NES requests by 3, which may affect the rate limit/user allowance. |
ef9c8d9 to
24edf6a
Compare
|
@avarayr Thanks for the PR! We'll take a detailed look. We are also working on additional approaches to improve the experience while keeping the number of requests in check. (E.g., microsoft/vscode#255727 and microsoft/vscode#255728.) |
69b2edb to
89154be
Compare
- Add prefetch chain mechanism that triggers when edits are shown - Prefetch up to 3 edits deep to reduce latency for sequential edits - Integrate with existing NextEditCache infrastructure - Track active prefetches to avoid duplicates - Clean up resources on disposal
89154be to
f21a024
Compare
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.
@avarayr Thanks again for the PR! I have left a few questions. Could you rebase/merge it with the latest from main?
Could you also add a setting to enable/disable it? We would keep this off by default at first, so we can get it well tested and estimate the number of additional LLM calls.
| } | ||
|
|
||
| // Create a unique key for this prefetch based on document state | ||
| const prefetchKey = `${docId}:${documentState.value.length}:${depth}`; |
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.
Since we only show one suggestion at a time, maybe there should be at most one active prefetch at a time? (Avoiding the need for a key here.)
| try { | ||
|
|
||
| // Create a synthetic document that represents the future state | ||
| const syntheticDoc = this._workspace.getDocument(docId); |
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.
This isn't used later?
|
|
||
| // Create a synthetic document wrapper that returns our future state | ||
| const syntheticDocWrapper = { | ||
| ...doc, |
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.
Not sure this is safe to copy like that, will need to take closer look.
| // Optimistic fetching already triggered in handleShown | ||
| } | ||
|
|
||
| public handleRejection(docId: DocumentId, suggestion: NextEditResult) { |
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.
Should the prefetch be canceled when the current suggestion is rejected? Similarly: What if the current suggestion is ignored (callback below).
Basis: Tab, Tab, Tab — Objects in motion want to stay in motion.
Summary
This PR implements optimistic prefetching for next edit suggestions, eliminating delay between accepting an edit and receiving the next suggestion by assuming that user will keep pressing tab to accept sequential edits.
Problem
Currently, when users accept an inline edit suggestion, there's a noticeable delay
before the next suggestion appears. This breaks the flow of rapid sequential edits.
Solution
Implement predictive fetching that anticipates user behavior based on the "objects in
motion stay in motion" principle. When a NES is shown, the system
immediately fetches the next edit in the background, assuming the user will continue
accepting suggestions.
All existing tests continue to pass.
Performance
Discussion
Optimistic NES will multiply the number of NES requests by 3, which may affect the rate limit/user allowance.