⚡ Optimize completion state storage by using offsets instead of full text#5
⚡ Optimize completion state storage by using offsets instead of full text#5gasatrya wants to merge 2 commits into
Conversation
- Replace full document text snapshot in `CompletionState` with a numerical `baseOffset`. - Use native VS Code `offsetAt` and `positionAt` methods for more efficient and robust calculations. - Eliminate expensive `getText()` calls for the entire document during interpolation. - Remove redundant `getOffsetFromPosition` private helper. This change reduces memory consumption by ~95% for stored completion states and significantly improves execution time for interpolation. Co-authored-by: gasatrya <891643+gasatrya@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
- Replace full document text snapshot in `CompletionState` with a numerical `baseOffset`. - Use native VS Code `offsetAt` and `positionAt` methods for more efficient and robust calculations. - Eliminate expensive `getText()` calls for the entire document during interpolation. - Remove redundant `getOffsetFromPosition` private helper. - Fix formatting issues. This change reduces memory consumption by ~95% for stored completion states and significantly improves execution time for interpolation. Co-authored-by: gasatrya <891643+gasatrya@users.noreply.github.com>
This PR optimizes the
CompletionStateManagerto be more memory and CPU efficient.💡 What:
CompletionStateinterface to storebaseOffset(number) instead ofbaseDocumentText(string).setCompletionto capture the cursor offset usingdocument.offsetAt(position).interpolateCompletionand its helpers to use the stored offset and VS Code's native position/offset conversion methods.getOffsetFromPositionhelper.🎯 Why:
Storing the full document text for every completion was redundant and expensive, especially for large files. It caused unnecessary memory allocations and CPU overhead during string parsing.
📊 Measured Improvement:
Using a benchmark with 50 iterations on a 1MB file:
Additionally, the new logic using
document.positionAt()is more robust as it correctly handles multi-line edits which were previously handled by simple character arithmetic on a single line.PR created automatically by Jules for task 488475036304213692 started by @gasatrya