Skip to content

Reduce allocations in GrpcMessageExtensionUtilities.ConvertFromHttpMessageToExpando #11054

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from

Conversation

kshyju
Copy link
Member

@kshyju kshyju commented May 5, 2025

Optimizations in GrpcMessageExtensionUtilities.ConvertFromHttpMessageToExpando method, which is a hotpath method and gets executed on every invocation in HTTP non-proxy use case.

  • Removed the use of the dynamic type to build the HTTP response object, eliminating late binding and runtime dispatch.
  • Replaced certain LINQ allocations.
  • Using cached boxed boolean values to avoid per request boxing.
  • Using a cached empty dictionary.

Improvements captured from benchmarking pipeline (Requests/sec - max) - 4 core machines.

Requests/sec (max)
Platform Before After Delta
Linux 10,894 12,743 +16.96%
Windows 15,248 17,111 +12.21%

With this change, app handles burst traffic better. Other core metrics, such as average RPS and memory usage, have remained stable or improved slightly.

I also collected perf profiles with a local load test run which sends stable traffic (1,000 requests)

Before

Name Total (Allocations) Self (Allocations) Total Size (Bytes) Self Size (Bytes)
ConvertFromHttpMessageToExpando(RpcHttp) 85,859 3,568 4,472,970 147,112

image

After

Name Total (Allocations) Self (Allocations) Total Size (Bytes) Self Size (Bytes)
ConvertFromHttpMessageToExpando(RpcHttp) 15,084 3,000 763,724 184,000
image

Delta

  • GrpcMessageExtensionUtilities.ConvertFromHttpMessageToExpando – Total allocations dropped by 70,775 (82.45%)
  • GrpcMessageExtensionUtilities.ConvertFromHttpMessageToExpando – Total allocated size dropped by 3.54 MB (82.92%)

#11040 added test coverage for this code path.

Pull request checklist

IMPORTANT: Currently, changes must be backported to the in-proc branch to be included in Core Tools and non-Flex deployments.

  • Backporting to the in-proc branch is not required
    • Otherwise: Link to backporting PR
  • My changes do not require documentation changes
    • Otherwise: Documentation issue linked to PR
  • My changes should not be added to the release notes for the next release
    • Otherwise: I've added my notes to release_notes.md
  • My changes do not need to be backported to a previous version
    • Otherwise: Backport tracked by issue/PR #issue_or_pr
  • My changes do not require diagnostic events changes
    • Otherwise: I have added/updated all related diagnostic events and their documentation (Documentation issue linked to PR)
  • I have added all required tests (Unit tests, E2E tests)

…eToExpando` method for improved performance.
@kshyju kshyju marked this pull request as ready for review May 5, 2025 23:17
@kshyju kshyju requested a review from a team as a code owner May 5, 2025 23:17
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