Skip to content

Optimizing ReadLanguageWorkerFile to avoid LOH allocations by reading files in chunks #11069

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 2 commits into from
May 21, 2025

Conversation

kshyju
Copy link
Member

@kshyju kshyju commented May 19, 2025

Optimized RpcWorkerConfigFactory.ReadLanguageWorkerFile to avoid LOH allocations by reading worker executable files in buffered chunks instead of using File.ReadAllBytes. The previous implementation loaded entire files into memory, resulting in LOH allocations and increased GC pressure. Since the method's main purpose is to preload files into the OS disk cache, reading in chunks achieves this efficiently, reducing memory usage and minimizing the likelihood of blocking GEN2 garbage collections.

Visual Studio

Before

image

After

image

DotMemory

Before

image image

After

image image

With the previous approach, the 120MB+ LOH allocation would persist until the next Gen2 GC (blocking). Change in this PR reduces the likelihood of triggering a Gen2 GC by avoiding large object heap allocations.

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 May 19, 2025 20:33
@kshyju kshyju requested a review from safihamid May 19, 2025 20:33
Copy link
Contributor

@safihamid safihamid left a comment

Choose a reason for hiding this comment

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

:shipit:

@kshyju kshyju merged commit 62f8d8a into dev May 21, 2025
9 checks passed
@kshyju kshyju deleted the shkr/dev_20250519+placeholder_trace branch May 21, 2025 01:22
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.

4 participants