Skip to content

Conversation

@markijbema
Copy link
Contributor

Implements Approach 3 (Hybrid - Request Deduplication with Intelligent Cancellation) to optimize autocomplete performance:

  • Add PendingSuggestion interface and pendingRequests Map to track in-flight API requests
  • Implement getCacheKey() for unique request identification
  • Implement findReusablePendingRequest() to intelligently reuse pending requests
  • Enhanced fetchAndCacheSuggestion() with:
    • Deduplication of identical requests (same prefix/suffix)
    • Reuse of pending requests when user types ahead
    • Automatic adjustment of suggestions to remove already-typed text
    • Cancellation of obsolete requests when prefix diverges
    • Proper cleanup of completed requests
  • Update dispose() to cancel all pending requests on cleanup
  • Add comprehensive test suite for request deduplication functionality

Benefits:

  • Prevents duplicate API calls for identical contexts
  • Reduces latency when user types ahead of completion
  • Maintains existing chunk-based architecture
  • Low risk, incremental improvement
  • Can evolve to full streaming approach later if needed

Context

Implementation

Screenshots

before after

How to Test

Get in Touch

@changeset-bot
Copy link

changeset-bot bot commented Nov 19, 2025

⚠️ No Changeset found

Latest commit: d7a0cfe

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@markijbema markijbema force-pushed the feature/ghost-request-deduplication branch from a4d75c3 to 57a28f0 Compare November 20, 2025 13:33
Implements Approach 3 (Hybrid - Request Deduplication with Intelligent Cancellation) to optimize autocomplete performance:

- Add PendingSuggestion interface and pendingRequests Map to track in-flight API requests
- Implement getCacheKey() for unique request identification
- Implement findReusablePendingRequest() to intelligently reuse pending requests
- Enhanced fetchAndCacheSuggestion() with:
  * Deduplication of identical requests (same prefix/suffix)
  * Reuse of pending requests when user types ahead
  * Automatic adjustment of suggestions to remove already-typed text
  * Cancellation of obsolete requests when prefix diverges
  * Proper cleanup of completed requests
- Update dispose() to cancel all pending requests on cleanup
- Add comprehensive test suite for request deduplication functionality

Benefits:
- Prevents duplicate API calls for identical contexts
- Reduces latency when user types ahead of completion
- Maintains existing chunk-based architecture
- Low risk, incremental improvement
- Can evolve to full streaming approach later if needed
Fixed timeout issues in request deduplication tests by ensuring all pending
debounce promises are properly resolved. The previous implementation would
create new promises on each call but never resolve old ones when the timer
was cleared and reset.

Changes:
- Added pendingDebounceResolvers array to track all promise resolvers
- Resolve all accumulated promises when debounce timer fires
- Distinguish between 'typing ahead' (reuse request) and 'diverging' (flush and start new)
- Clear pending resolvers in dispose() method
- Updated test helpers to properly handle async timer advancement

All 5458 tests now pass, including the 5 request deduplication tests that
were previously timing out after 20 seconds.
@markijbema markijbema force-pushed the feature/ghost-request-deduplication branch from 57a28f0 to 68c9e6d Compare November 21, 2025 16:23
…sses

- Create RequestDebouncer class to handle debouncing logic separately
- Create RequestDeduplicator class to manage request deduplication
- Refactor GhostInlineCompletionProvider to use helper classes
- Add comprehensive test coverage for both helper classes (26 tests)
- Reduce state management complexity from 3 variables to 2 helper instances
- Extract helper methods: adjustSuggestion(), isAbortError(), executeRequest()
- Add PR review document analyzing complexity vs original implementation
- Add complexity reduction plan with detailed refactoring strategy

Benefits:
- Better separation of concerns
- Improved testability and maintainability
- Reduced cognitive complexity in main provider class
- Each component can be tested and modified independently
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.

2 participants