-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Performance: Optimize memory footprint of document URL cache (closes #21055) #21066
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
base: main
Are you sure you want to change the base?
Conversation
3a3ae29 to
a9806fc
Compare
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 the memory footprint of the document URL cache in Umbraco CMS, achieving approximately 58% memory reduction (from 527MB to 236MB with 1.4M documents, and from 80KB to 34KB with 218 documents) without sacrificing performance.
Key Changes:
- Replaced verbose string-based cache keys with a compact struct (
UrlCacheKey) usingintlanguage IDs instead of culture strings - Implemented a more memory-efficient cache value structure (
UrlSegmentCache) that stores the primary segment directly and only allocates an array for alternate segments when needed (rare case) - Added a culture-to-language-ID mapping cache to enable the use of integer IDs for lookups
- Introduced memory usage calculation and logging for better observability
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/Umbraco.Core/Services/DocumentUrlService.cs | Core implementation: Introduced UrlCacheKey struct and UrlSegmentCache class for memory-efficient caching, refactored cache storage from string keys to struct keys, added culture-to-language-ID mapping, implemented memory usage calculation, and updated all cache operations (init, lookup, update, remove) to use the new structures |
| tests/Umbraco.Tests.UnitTests/Umbraco.Core/Services/DocumentUrlServiceTests.cs | Updated unit tests to validate the new cache model structure (Key/Cache tuple instead of single object), verified correct handling of primary/alternate segments, and updated performance benchmark comments to reflect the current implementation |
tests/Umbraco.Tests.UnitTests/Umbraco.Core/Services/DocumentUrlServiceTests.cs
Outdated
Show resolved
Hide resolved
…lServiceTests.cs Co-authored-by: Copilot <[email protected]>
…isn't up to date with the newly created languages.
Prerequisites
Addresses #21055
Description
The linked issue raises the concern of the memory footprint of the document URL cache, which is loaded on start-up and held for the lifetime of the application.
My understanding with the introduction of the Hybrid cache was that this was deliberately separated out, so we guarantee URLs are in the cache for routing, but can lazy load documents. So I haven't looked at lazy loading of document URLs as a solution to this.
Rather it seems we can optimize quite a bit the amount of memory the cache takes up. Having done some analysis on it it's apparent we can improve in a few areas:
I see some significant improvements - ~58% - with a small and quite large database (these figures compare the current implementation with the one in this PR):
Testing
Verify existing integration tests pass and via manual testing that documents can be routed.