Skip to content

perf(grpc-js): cache precomputed serviceUrl in InternalChannel - #3097

Open
olavloite wants to merge 4 commits into
grpc:masterfrom
olavloite:cache-precomputed-service-url
Open

olavloite wants to merge 4 commits into
grpc:masterfrom
olavloite:cache-precomputed-service-url

Conversation

@olavloite

Copy link
Copy Markdown
Contributor

Cache the precomputed serviceUrl used by call credentials in a bounded two-level cache on InternalChannel instead of re-parsing the method path, splitting the host, and constructing a new template string on every RPC.

  • Add zero-allocation extractServiceName and computeServiceUrl helpers in uri-parser.ts.
  • Introduce a bounded two-level cache (serviceUrlCache: Map<string, Map<string, string>>) on InternalChannel, capped at 5 hosts and 100 methods per host to strictly bound memory while achieving zero-allocation lookups on cache hits.
  • Clear serviceUrlCache when the channel is closed.
  • Update LoadBalancingCall and SingleSubchannelChannel to use the shared URL computation and caching.

Cache the precomputed serviceUrl used by call credentials in a bounded
two-level cache on InternalChannel instead of re-parsing the method path,
splitting the host, and constructing a new template string on every RPC.

- Add zero-allocation `extractServiceName` and `computeServiceUrl` helpers
  in `uri-parser.ts`.
- Introduce a bounded two-level cache (`serviceUrlCache: Map<string, Map<string, string>>`)
  on `InternalChannel`, capped at 5 hosts and 100 methods per host to
  strictly bound memory while achieving zero-allocation lookups on cache hits.
- Clear `serviceUrlCache` when the channel is closed.
- Update `LoadBalancingCall` and `SingleSubchannelChannel` to use the
  shared URL computation and caching.
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