Skip to content

Conversation

@MihaZupan
Copy link
Member

@MihaZupan MihaZupan commented Jul 18, 2025

Fixes #117777

Instead of copying the whole remainder any time we want to remove a section, we now store a list of all removed sections and only do one copying pass at the end.

The actual product change is just fcb5287, the rest is moving stuff around for testing.

This method could be simplified further, I just avoided doing so in this PR to keep things reviewable.

@MihaZupan MihaZupan added this to the 10.0.0 milestone Jul 18, 2025
@MihaZupan MihaZupan requested a review from a team July 18, 2025 16:12
@MihaZupan MihaZupan self-assigned this Jul 18, 2025
Copilot AI review requested due to automatic review settings July 18, 2025 16:12
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 Uri path compression from O(n²) to O(n) complexity by deferring the copying of segments until the end. Instead of copying the whole remainder of the path every time a section needs to be removed, the new implementation stores a list of removed sections and performs a single copying pass at the end.

Key changes:

  • Moved path compression logic from Uri.cs to UriHelper.cs and made it more efficient
  • Replaced ArrayBuilder with ValueListBuilder for better performance
  • Added comprehensive regression tests to ensure the optimization doesn't break existing functionality

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/libraries/System.Private.Uri/src/System/UriHelper.cs Added new optimized Compress method using ValueListBuilder to track removed segments
src/libraries/System.Private.Uri/src/System/Uri.cs Removed old O(n²) compression implementation and updated calls to use new UriHelper.Compress method
src/libraries/System.Private.Uri/src/System.Private.Uri.csproj Replaced ArrayBuilder reference with ValueListBuilder
src/libraries/System.Private.Uri/tests/UnitTests/System.Private.Uri.Unit.Tests.csproj Added test file reference and ValueListBuilder dependency for testing
src/libraries/System.Private.Uri/tests/UnitTests/PathCompressionTests.cs Added regression tests comparing old and new compression implementations

@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to this area: @dotnet/ncl
See info in area-owners.md if you want to be subscribed.

Copy link
Member

@rokonec rokonec left a comment

Choose a reason for hiding this comment

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

Awesome work! Guess LeetCode's not just a brain teaser after all! 😄

@MihaZupan MihaZupan force-pushed the uri-compress-complex2 branch from fcb5287 to daad517 Compare July 22, 2025 09:51
@MihaZupan MihaZupan enabled auto-merge (squash) July 22, 2025 09:59
@MihaZupan
Copy link
Member Author

/ba-g Build analysis isn't picking up WASM queue timeouts

@MihaZupan MihaZupan merged commit 42a2f25 into dotnet:main Jul 23, 2025
79 of 87 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Aug 23, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Uri path compression is O(n^2)

3 participants