Skip to content

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

avarayr
Copy link

@avarayr avarayr commented Jul 11, 2025

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

  • Reduces next edit latency from ~300ms to <10ms for predicted cases
  • No impact on initial suggestion performance
  • Minimal memory overhead with automatic cleanup

Discussion

Optimistic NES will multiply the number of NES requests by 3, which may affect the rate limit/user allowance.

@avarayr avarayr changed the title feat: add optimistic fetching for next edit suggestions Speculative fetching for Next Edit Suggestions Jul 11, 2025
@avarayr avarayr changed the title Speculative fetching for Next Edit Suggestions Optimistic Next Edit Suggestions Jul 11, 2025
@avarayr avarayr marked this pull request as ready for review July 11, 2025 21:01
@avarayr avarayr marked this pull request as draft July 11, 2025 22:25
@avarayr
Copy link
Author

avarayr commented Jul 11, 2025

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.
This is one of the things that Cursor got right, hopefully we can bridge the gap.

some points for discussion:

Optimistic NES will multiply the number of NES requests by 3, which may affect the rate limit/user allowance.

@avarayr avarayr marked this pull request as ready for review July 11, 2025 23:32
@bhavyaus bhavyaus requested a review from ulugbekna July 13, 2025 15:54
@avarayr avarayr force-pushed the feature/optimistic-next-edit-fetching branch 4 times, most recently from ef9c8d9 to 24edf6a Compare July 17, 2025 01:44
@chrmarti
Copy link
Collaborator

@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.)

@avarayr avarayr force-pushed the feature/optimistic-next-edit-fetching branch 3 times, most recently from 69b2edb to 89154be Compare July 20, 2025 18:52
- 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
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.

4 participants