Skip to content

Optimize initialization of document URLs on start-up#19498

Merged
nikolajlauridsen merged 2 commits intomainfrom
v16/bugfix/resolve-performance-degradation-on-startup
Jun 10, 2025
Merged

Optimize initialization of document URLs on start-up#19498
nikolajlauridsen merged 2 commits intomainfrom
v16/bugfix/resolve-performance-degradation-on-startup

Conversation

@AndyButland
Copy link
Contributor

@AndyButland AndyButland commented Jun 6, 2025

Prerequisites

  • I have added steps to test this contribution in the description below

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 List is exponentially slower than an implementation with a Dictionary as 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.

Copilot AI review requested due to automatic review settings June 6, 2025 15:10
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 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 ConvertToCacheModel to use a Dictionary<(DocumentKey, LanguageId, IsDraft), …> for O(1) grouping instead of O(n²)
  • Updates the PublishedDocumentUrlSegments model to be internal with 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

Copy link
Contributor

@nikolajlauridsen nikolajlauridsen left a comment

Choose a reason for hiding this comment

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

Looks good, tests good 👍

@nikolajlauridsen nikolajlauridsen added category/performance Fixes for performance (generally cpu or memory) fixes type/bug release/16.0.0-rc6 labels Jun 10, 2025
@nikolajlauridsen nikolajlauridsen self-assigned this Jun 10, 2025
@nikolajlauridsen nikolajlauridsen merged commit 8d2ff6f into main Jun 10, 2025
24 of 25 checks passed
@nikolajlauridsen nikolajlauridsen deleted the v16/bugfix/resolve-performance-degradation-on-startup branch June 10, 2025 08:28
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

category/performance Fixes for performance (generally cpu or memory) fixes release/16.0.0-rc6

Projects

None yet

Development

Successfully merging this pull request may close these issues.

V15.4 startup performance degradation (DocumentUrlService?)

3 participants