Skip to content

perf(grpc-js): avoid Date allocations on request and channelz tracking paths - #3090

Merged
murgatroid99 merged 2 commits into
grpc:masterfrom
olavloite:avoid-date-allocations
Sep 25, 2026
Merged

murgatroid99 merged 2 commits into
grpc:masterfrom
olavloite:avoid-date-allocations

Conversation

@olavloite

Copy link
Copy Markdown
Contributor

Store timestamps as epoch milliseconds (Date.now()) instead of allocating Date objects on the request path and channelz counters:

  • Call layers (ResolvingCall, RetryingCall, LoadBalancingCall): store call start and resolution times as numbers; construct Date instances only when formatting deadline error messages or when trace logging is enabled.
  • Channelz call tracker and HTTP/2 transport: record last call started, message sent, and message received timestamps as numbers.
  • Channel activity tracking: record channel idle timestamp as a number.
  • Server timeout handling: calculate incoming call deadlines with Date.now() + timeout instead of allocating a Date object.
  • dateToProtoTimestamp: support numeric millisecond timestamps in addition to Date objects, and use Math.floor() to avoid 32-bit integer overflow beyond year 2038.
  • formatDateDifference: accept numeric timestamps as well as Date instances.
  • Update channelz and deadline tests for numeric timestamps.

…g paths

Store timestamps as epoch milliseconds (Date.now()) instead of allocating
Date objects on the request path and channelz counters:
- Call layers (ResolvingCall, RetryingCall, LoadBalancingCall): store
  call start and resolution times as numbers; construct Date instances
  only when formatting deadline error messages or when trace logging is
  enabled.
- Channelz call tracker and HTTP/2 transport: record last call started,
  message sent, and message received timestamps as numbers.
- Channel activity tracking: record channel idle timestamp as a number.
- Server timeout handling: calculate incoming call deadlines with
  Date.now() + timeout instead of allocating a Date object.
- dateToProtoTimestamp: support numeric millisecond timestamps in
  addition to Date objects, and use Math.floor() to avoid 32-bit integer
  overflow beyond year 2038.
- formatDateDifference: accept numeric timestamps as well as Date
  instances.
- Update channelz and deadline tests for numeric timestamps.
@murgatroid99
murgatroid99 merged commit cd7adce into grpc:master Sep 25, 2026
9 of 10 checks passed
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