-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Make Uri path compression O(n) #117820
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
Make Uri path compression O(n) #117820
Conversation
There was a problem hiding this 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 |
|
Tagging subscribers to this area: @dotnet/ncl |
rokonec
left a comment
There was a problem hiding this 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! 😄
fcb5287 to
daad517
Compare
|
/ba-g Build analysis isn't picking up WASM queue timeouts |
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.