Skip to content

[api] Add option to collect timing info#4512

Merged
andrewbranch merged 7 commits into
microsoft:mainfrom
andrewbranch:api-timings
Jul 2, 2026
Merged

[api] Add option to collect timing info#4512
andrewbranch merged 7 commits into
microsoft:mainfrom
andrewbranch:api-timings

Conversation

@andrewbranch

Copy link
Copy Markdown
Member
const api = new API({ collectTiming: true });
// ... do stuff
console.log(api.getTimingInfo())
{
  enabled: true,
  totals: {
    requestCount: 2440,
    totalRoundTripMs: 63.988530000000196,
    totalBytesSent: 495494,
    totalBytesReceived: 5162079,
    totalServerTimeMs: 32.765000000000235,
    totalTransportOverheadMs: 31.223529999999798
  },
  recentRequests: [
    {
      method: 'getSymbolAtLocation',
      roundTripMs: 0.009291999999987866,
      bytesSent: 235,
      bytesReceived: 292,
      serverTimeMs: 0.002,
      transportOverheadMs: 0.0072919999999878655,
      timestamp: 1782940771785
    },
    {
      method: 'getAliasedSymbol',
      roundTripMs: 0.010958000000002244,
      bytesSent: 135,
      bytesReceived: 639,
      serverTimeMs: 0.004,
      transportOverheadMs: 0.006958000000002244,
      timestamp: 1782940771785
    },
    {
      method: 'getTypeAtLocation',
      roundTripMs: 0.01029199999999264,
      bytesSent: 250,
      bytesReceived: 108,
      serverTimeMs: 0.003,
      transportOverheadMs: 0.00729199999999264,
      timestamp: 1782940771785
    },
    {
      method: 'getSymbolOfType',
      roundTripMs: 0.008875000000003297,
      bytesSent: 136,
      bytesReceived: 297,
      serverTimeMs: 0.001,
      transportOverheadMs: 0.007875000000003296,
      timestamp: 1782940771785
    },
    {
      method: 'getMembersOfSymbol',
      roundTripMs: 0.01187500000000341,
      bytesSent: 137,
      bytesReceived: 453,
      serverTimeMs: 0.004,
      transportOverheadMs: 0.00787500000000341,
      timestamp: 1782940771785
    }
  ]
}

Copilot AI review requested due to automatic review settings July 1, 2026 21:27

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds an opt-in per-request timing/transfer measurement facility to the native API surface, allowing clients to collect round-trip latency, bytes sent/received, and server processing time (when available) and retrieve it via getTimingInfo().

Changes:

  • Add server-side timing collection plumbing, emitting server processing time over MessagePack (footer) and JSON-RPC (result envelope).
  • Add client-side timing aggregation/exposure (getTimingInfo, resetTimingInfo) for both sync and async native-preview clients, plus a collectTiming option and --timing flag.
  • Add protocol- and integration-level tests covering timing metadata and aggregation.

Reviewed changes

Copilot reviewed 17 out of 17 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
internal/api/server.go Adds CollectTiming option and wires it into conn setup.
internal/api/protocol.go Introduces serverTimedResult + helpers for timing metadata propagation.
internal/api/protocol_msgpack.go Appends a 4-byte timing footer to MessagePack responses when enabled.
internal/api/protocol_jsonrpc.go Wraps JSON-RPC results in a timing envelope when enabled.
internal/api/conn_sync.go Measures request duration and attaches timing metadata to successful responses.
internal/api/conn_async.go Measures request duration and attaches timing metadata to successful responses.
internal/api/protocol_msgpack_timing_test.go Adds tests for footer/envelope behavior and duration clamping.
cmd/tsgo/api.go Adds --timing flag to enable server timing metadata.
_packages/native-preview/src/api/options.ts Adds collectTiming option for spawned clients.
_packages/native-preview/src/api/timing.ts Implements client-side timing collector/types.
_packages/native-preview/src/api/syncChannel.ts Strips MessagePack timing footer and tracks per-request byte/timing fields.
_packages/native-preview/src/api/sync/client.ts Records per-request timings and exposes get/reset APIs (sync).
_packages/native-preview/src/api/sync/api.ts Re-exports timing types and exposes API-level get/reset (sync).
_packages/native-preview/src/api/async/client.ts Records per-request timings via JSON-RPC envelope and exposes get/reset APIs (async).
_packages/native-preview/src/api/async/api.ts Re-exports timing types and exposes API-level get/reset (async).
_packages/native-preview/test/sync/api.test.ts Adds sync integration tests for timing collection behavior.
_packages/native-preview/test/async/api.test.ts Adds async integration tests for timing collection behavior.

Comment thread _packages/native-preview/src/api/timing.ts
Comment thread internal/api/server.go Outdated
Comment thread internal/api/conn_sync.go
Comment thread internal/api/conn_async.go

@jakebailey jakebailey left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems a little funky; we can't just collect this info out of band and then query it, rather than framing every message differently? It's probably okay, just thinking about it long term

@andrewbranch

Copy link
Copy Markdown
Member Author

That would work, yeah. I wasn't too happy with changing the shape of the JSON-RPC messages, but it didn't end up being much code, and I think I want to replace JSON-RPC eventually here (going in and out of base64 for binary is a little expensive).

@andrewbranch

Copy link
Copy Markdown
Member Author

I think your suggestion is ultimately simpler, though probably a slight increase in LOC. Let me try it and see.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 16 out of 16 changed files in this pull request and generated 2 comments.

Comment thread internal/api/timing.go
Comment thread _packages/native-preview/src/api/syncChannel.ts Outdated
@andrewbranch

Copy link
Copy Markdown
Member Author

I had the idea this morning to add some client-side timing info on cumulative RemoteNode materialization from source file buffers, so I'm throwing that together.

@andrewbranch

Copy link
Copy Markdown
Member Author

Per-node materialization is too fast to measure very well, but we can at least see how many source files were fetched, how many nodes that represents, and how many of those nodes were ever materialized.

@andrewbranch andrewbranch added this pull request to the merge queue Jul 2, 2026
Merged via the queue into microsoft:main with commit 99fbd74 Jul 2, 2026
21 checks passed
@andrewbranch andrewbranch deleted the api-timings branch July 2, 2026 18:05
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.

3 participants