Skip to content

Commit 6e91b53

Browse files
authored
progressive rendering: use the previous word count for the word rate (#198560)
* progressive rendering: use the previous word count for the word rate
1 parent ad31b06 commit 6e91b53

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

src/vs/workbench/contrib/chat/common/chatViewModel.ts

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ export interface IChatLiveUpdateData {
7979
loadingStartTime: number;
8080
lastUpdateTime: number;
8181
impliedWordLoadRate: number;
82+
lastWordCount: number;
8283
}
8384

8485
export interface IChatResponseViewModel {
@@ -372,7 +373,8 @@ export class ChatResponseViewModel extends Disposable implements IChatResponseVi
372373
this._contentUpdateTimings = {
373374
loadingStartTime: Date.now(),
374375
lastUpdateTime: Date.now(),
375-
impliedWordLoadRate: 0
376+
impliedWordLoadRate: 0,
377+
lastWordCount: 0
376378
};
377379
}
378380

@@ -382,18 +384,14 @@ export class ChatResponseViewModel extends Disposable implements IChatResponseVi
382384
const now = Date.now();
383385
const wordCount = countWords(_model.response.asString());
384386
const timeDiff = now - this._contentUpdateTimings!.loadingStartTime;
385-
const impliedWordLoadRate = wordCount / (timeDiff / 1000);
386-
const renderedWordCount = this.renderData?.renderedParts.reduce((acc, part) => acc += ('label' in part ? 0 : part.renderedWordCount), 0);
387-
if (!this.isComplete) {
388-
this.trace('onDidChange', `Update- got ${wordCount} words over ${timeDiff}ms = ${impliedWordLoadRate} words/s. ${renderedWordCount} words are rendered.`);
389-
this._contentUpdateTimings = {
390-
loadingStartTime: this._contentUpdateTimings!.loadingStartTime,
391-
lastUpdateTime: now,
392-
impliedWordLoadRate
393-
};
394-
} else {
395-
this.trace(`onDidChange`, `Done- got ${wordCount} words over ${timeDiff}ms = ${impliedWordLoadRate} words/s. ${renderedWordCount} words are rendered.`);
396-
}
387+
const impliedWordLoadRate = this._contentUpdateTimings.lastWordCount / (timeDiff / 1000);
388+
this.trace('onDidChange', `Update- got ${this._contentUpdateTimings.lastWordCount} words over ${timeDiff}ms = ${impliedWordLoadRate} words/s. ${wordCount} words are now available.`);
389+
this._contentUpdateTimings = {
390+
loadingStartTime: this._contentUpdateTimings!.loadingStartTime,
391+
lastUpdateTime: now,
392+
impliedWordLoadRate,
393+
lastWordCount: wordCount
394+
};
397395
} else {
398396
this.logService.warn('ChatResponseViewModel#onDidChange: got model update but contentUpdateTimings is not initialized');
399397
}

0 commit comments

Comments
 (0)