Skip to content

Conversation

@Erarndt
Copy link
Contributor

@Erarndt Erarndt commented Sep 26, 2025

Fixes #

Context

In most cases, an expression will only have one capture. We can optimize for that case and avoid allocating a size 4 array (list default) just to hold one element.

Before:
image

After:
image

This saves ~150MB

Changes Made

Testing

Notes

Copilot AI review requested due to automatic review settings September 26, 2025 20:09
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR optimizes memory allocation for expression captures by specifying an initial capacity of 1 when creating List instances, based on the observation that most expressions contain only a single capture. This avoids the default capacity of 4, reducing memory overhead.

Key changes:

  • Modified List constructor calls to specify initial capacity of 1 for transformExpressions
  • Added performance comments explaining the optimization rationale

@JanProvaznik JanProvaznik merged commit 8fb7c0b into dotnet:main Oct 21, 2025
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