Skip to content

Conversation

github-actions[bot]
Copy link
Contributor

@github-actions github-actions bot commented Mar 26, 2024

Backport of #54479 to release/8.0

/cc @JamesNK

Fix route analyzer performance with highly concatenated strings

Route analyzer introduced in .NET 8 can cause very long build times in some projects. A highly concatenated string in a C# file causes a lot of time to be spent in Roslyn's GetLeadingTrivia method. Many concatenated strings cause O(N^2) calls to this relatively expensive method.

For example, "x1" + "x2" + "x3" + "x4" + ... "x1000" will greatly increase build times by calling GetLeadingTrivia 1 million times. There isn't a limit to the number of string concats so performance gets worse the more string concats.

The fix is to skip analyzing concatenated strings. This improves performance and is better behavior. The analyzer isn't designed to analyze content spread across multiple string fragments. Note that Roslyn has the same issue (although their performance impact is smaller) and has implemented the same code fix - dotnet/roslyn#72620.

Fixes #54293
Fixes #53899

Customer Impact

Multiple customers have reported 5+ second increase in build time. They have code generation tools that produce hundreds of string concats in output C#.

Customers can work around this issue by disabling the slow analyzer. However, there is no indication that poor performance is linked to an analyzer. Customers are unlikely to find the fix themselves.

Regression?

  • Yes
  • No

Projects with highly concatenated strings that are built fast in .NET 7 are slow after updating to .NET 8.

Risk

  • High
  • Medium
  • Low

A small, isolated change to an analyzer.

Verification

  • Manual (required)
  • Automated

Manual testing using the framework samples project (note: part of aspnetcore solution so build performance has some overhead)

Before:

========== Build completed at 10:23 am and took 15.319 seconds ==========

After:

========== Build completed at 10:24 am and took 04.123 seconds ==========

Packaging changes reviewed?

  • Yes
  • No
  • N/A

When servicing release/2.1

  • Make necessary changes in eng/PatchConfig.props

@ghost ghost added the area-infrastructure Includes: MSBuild projects/targets, build scripts, CI, Installers and shared framework label Mar 26, 2024
@dotnet-policy-service dotnet-policy-service bot added this to the 8.0.x milestone Mar 26, 2024
@JamesNK
Copy link
Member

JamesNK commented Mar 26, 2024

FYI @CyrusNajmabadi @cston @jjonescz

@JamesNK JamesNK added the Servicing-consider Shiproom approval is required for the issue label Mar 26, 2024
@mkArtakMSFT mkArtakMSFT added area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc and removed area-infrastructure Includes: MSBuild projects/targets, build scripts, CI, Installers and shared framework labels Mar 28, 2024
@JamesNK JamesNK added Servicing-approved Shiproom has approved the issue and removed Servicing-consider Shiproom approval is required for the issue labels Apr 2, 2024
@JamesNK JamesNK modified the milestones: 8.0.x, 8.0.5 Apr 2, 2024
This was referenced Aug 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc Servicing-approved Shiproom has approved the issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants