-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Cody: Add a cache for inline completions #51046
Conversation
I think I'll need to do this right away, 10 characters is just too weirdly arbitrary after some more testing (especially since VS Code doesn't even seem to return completions while typing mid-word, so 10 character barely manages to show up a second time (after ~1 word) |
client/cody/src/completions/cache.ts
Outdated
public get(prefix: string): Completion[] | undefined { | ||
const results = this.cache.get(prefix) | ||
if (results) { | ||
console.log('CACHE HIT') |
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.
console.log('CACHE HIT') |
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.
😐
) | ||
} | ||
|
||
// TODO(beyang): trigger on context quality (better context means longer completion) | ||
|
||
const waiter = new Promise<void>(resolve => | ||
await new Promise<void>(resolve => |
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.
🔪👨🏻🍳😄 (killed the waiter—only found cook emoji)
This adds a simple LRU cache for completions with the main goal to further reduce the number of requests and reduce annoying churn in the scenario where a user receives a completion and types the exact same characters. Previously, the new characters would cause a new completion request which could yield different result.
Here's an example of how this cache works:
i < files.length; i++) {
\n
) of the input prefix by concatenating characters from the completion (Only using the last line here to visualize):for(let i = 0;
for(let i = 0;
for(let i = 0; i
for(let i = 0; i
for(let i = 0; i <
for(let i = 0; i <
for(let i = 0; i < f
for(let i = 0; i < fi
for(let i = 0; i < fil
for(let i = 0; i < file
Additional thoughts
prompt
as part of theCompletion
interface which may not be necessary.\n
to the prefix. These can now be reused if you type enter and will result in a faster suggestion for the next line.Test plan
I've added a
console.log
when a cache hit is encountered to visualize it while playing around with it:Screen.Recording.2023-04-24.at.17.54.08.mov