1
>
/*---------------------------------------------------------------------------------------------
chatPerf.ts
2
>
* Copyright (c) Microsoft Corporation. All rights reserved.
3
>
* Licensed under the MIT License. See License.txt in the project root for license information.
4
>
*--------------------------------------------------------------------------------------------*/
5
>
6
>
import { mark, clearMarks } from '../../../../base/common/performance.js';
7
>
import { URI } from '../../../../base/common/uri.js';
8
>
import { chatSessionResourceToId } from './model/chatUri.js';
9
>
10
>
const chatPerfPrefix = 'code/chat/';
11
>
12
>
/** Tracks all mark names emitted per session so they can be cleared individually. */
13
>
const chatMarksBySession = new Map<string, Set<string>>();
14
>
15
>
/**
16
>
* Well-defined perf scenarios for chat request lifecycle.
17
>
* Each mark is a boundary of a measurable scenario — don't add marks
18
>
* without defining what scenario they belong to.
19
>
*
20
>
* ## Scenarios
21
>
*
22
>
* **Time to UI Feedback** (perceived input lag):
23
>
* `request/start` → `request/uiUpdated`
24
>
*
25
>
* **Instruction Collection Overhead**:
26
>
* `request/willCollectInstructions` → `request/didCollectInstructions`
27
>
*
28
>
* **Extension Activation Wait** (first-request cold start):
29
>
* `code/chat/willWaitForActivation` → `code/chat/didWaitForActivation`
30
>
* (global marks, not session-scoped — emitted via {@link markChatGlobal})
31
>
*
32
>
* **Time to First Token** (the headline metric):
33
>
* `request/start` → `request/firstToken`
34
>
*
35
>
* **Total Request Duration**:
36
>
* `request/start` → `request/complete`
37
>
*
38
>
* **Agent Invocation Time** (LLM round-trip):
39
>
* `agent/willInvoke` → `agent/didInvoke`
40
>
*/
41
>
export const ChatPerfMark = {
42
>
/** User pressed Enter / request initiated */
43
>
RequestStart: 'request/start',
44
>
/** Request added to model → UI shows the message */
45
>
RequestUiUpdated: 'request/uiUpdated',
46
>
/** Begin collecting .instructions.md / skills / hooks */
47
>
WillCollectInstructions: 'request/willCollectInstructions',
48
>
/** Done collecting instructions */
49
>
DidCollectInstructions: 'request/didCollectInstructions',
50
>
/** First streamed response content received */
51
>
FirstToken: 'request/firstToken',
52
>
/** Response fully complete */
53
>
RequestComplete: 'request/complete',
54
>
/** Agent invoke begins (LLM round-trip start) */
55
>
AgentWillInvoke: 'agent/willInvoke',
56
>
/** Agent invoke returns (LLM round-trip end) */
57
>
AgentDidInvoke: 'agent/didInvoke',
58
>
} as const;
59
>
60
>
/**
61
>
* Emits a performance mark scoped to a chat session:
62
>
* `code/chat/<sessionResource>/<name>`
63
>
*
64
>
* Marks are automatically cleaned up when the corresponding chat model is
65
>
* disposed — see {@link clearChatMarks}.
66
>
*/
67
>
export function markChat(sessionResource: URI, name: string): void {
68
const sessionId = chatSessionResourceToId(sessionResource);
69
const fullName = `${chatPerfPrefix}${sessionId}/${name}`;