Optimize initialization of document URLs on start-up#19498
Merged
nikolajlauridsen merged 2 commits intomainfrom Jun 10, 2025
Merged
Optimize initialization of document URLs on start-up#19498nikolajlauridsen merged 2 commits intomainfrom
nikolajlauridsen merged 2 commits intomainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR optimizes the start-up conversion of persisted document URLs by replacing a linear lookup on a List with a Dictionary-based grouping for significantly improved performance.
- Refactors
ConvertToCacheModelto use aDictionary<(DocumentKey, LanguageId, IsDraft), …>for O(1) grouping instead of O(n²) - Updates the
PublishedDocumentUrlSegmentsmodel to beinternalwith XML documentation and replaces inlined helper methods with dictionary lookups - Adds comprehensive unit tests (including a performance benchmark) to validate correctness and measure the speedup
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| tests/Umbraco.Tests.UnitTests/Umbraco.Core/Services/DocumentUrlServiceTests.cs | Adds unit tests covering single/multiple documents and segments, plus a performance benchmark |
| src/Umbraco.Core/Services/DocumentUrlService.cs | Refactors ConvertToCacheModel, introduces dictionary grouping, updates model visibility and XML docs |
tests/Umbraco.Tests.UnitTests/Umbraco.Core/Services/DocumentUrlServiceTests.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: Copilot <[email protected]>
nikolajlauridsen
approved these changes
Jun 10, 2025
Contributor
nikolajlauridsen
left a comment
There was a problem hiding this comment.
Looks good, tests good 👍
nikolajlauridsen
pushed a commit
that referenced
this pull request
Jun 10, 2025
* Optimize initialization of document URLs on startup. * Apply suggestions from code review Co-authored-by: Copilot <[email protected]> --------- Co-authored-by: Copilot <[email protected]> (cherry picked from commit 8d2ff6f)
AndyButland
added a commit
that referenced
this pull request
Jun 10, 2025
* Optimize initialization of document URLs on startup. * Apply suggestions from code review Co-authored-by: Copilot <[email protected]> --------- Co-authored-by: Copilot <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Prerequisites
Resolves #19497 reporting a significant deterioration in start-up time for sites with many published documents.
Description
The linked issue reveals a poor choice of data structure used to convert the persisted document URLs (stored with a record for each document/language/state/segment) to the model used for caching. This runs on start-up for all document URLs and the existing use of a
Listis exponentially slower than an implementation with aDictionaryas provided here. And as the benchmark unit test has shown.The regression was introduced via #18603.
Testing
Verify existing integration tests pass and check routing of a document requested via it's URL works as expected.