Skip to content

Reduce allocations in RpcWorkerConfigFactory.AddProviders #10959

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

Merged
merged 10 commits into from
Apr 16, 2025

Conversation

kshyju
Copy link
Member

@kshyju kshyju commented Mar 26, 2025

resolves #10931

  1. Replaced Newtonsoft.Json with System.Text.Json for deserializing worker profiles.
  2. Previously, all worker configs were loaded and parsed into RpcWorkerDescription objects before filtering using ShouldAddWorkerConfig. Now, we skip loading configs for non-matching runtimes and only parse the config that matches FUNCTIONS_WORKER_RUNTIME, reducing unnecessary overhead after specialization.

This change reduced allocations in the AddProviders method, during specialization (and even during placeholder mode).

Before

Function Name Total (Allocations) Self (Allocations) Total Size (Bytes) Self Size (Bytes)
RpcWorkerConfigFactory.GetConfigs() 5,618 6 536,320 192
RpcWorkerConfigFactory.AddProviders() 5,039 2 481,990 64
RpcWorkerConfigFactory.AddProvider(string) 4,997 30 476,358 1,040

After

Function Name Total (Allocations) Self (Allocations) Total Size (Bytes) Self Size (Bytes)
RpcWorkerConfigFactory.GetConfigs() 3,961 6 271,511 192
RpcWorkerConfigFactory.AddProviders() 3,521 2 243,522 64
RpcWorkerConfigFactory.AddProvider(string) 3,479 16 237,890 592

Delta

  • RpcWorkerConfigFactory.AddProviders() - Total allocations dropped by 1,518 (30.13%).
  • RpcWorkerConfigFactory.AddProviders() - Total allocated size reduced by ~238 KB (nearly 50%).

Before

image

After

image

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)

Additional information

Additional PR information

@kshyju kshyju requested a review from a team as a code owner March 26, 2025 20:05
@kshyju kshyju requested a review from safihamid March 26, 2025 20:06
Copy link
Member

@liliankasem liliankasem left a comment

Choose a reason for hiding this comment

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

minor comments but lgtm

@kshyju kshyju merged commit 74d7ccc into dev Apr 16, 2025
9 checks passed
@kshyju kshyju deleted the shkr/dev_0326+add_providers branch April 16, 2025 18:57
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.

Optimize RpcWorkerConfigFactory.AddProvider method
4 participants