all: Rework page store, add a dynacache to enable bigger data/content, and some general spring cleaning #11830
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.
This PR is big. I could/should probably try to split it, but the pieces are in many ways related, and splitting it would be hard.
There are some breaking changes in this commit, see #11455.
Closes #11455
Closes #11549
What Changed
This fixes a set of bugs (see issue list) and it is also paying some technical debt accumulated over the years. We now finally builds with Staticcheck enabled in the CI build.
The performance should be about the same for regular sized Hugo sites, but it should perform and scale much better to larger data sets, as objects that uses lots of memory (e.g. rendered Markdown, big JSON files read into maps with transform.Unmarshal etc.) will now get automatically garbage collected if needed. Performance on partial rebuilds when running the server in fast render mode should be the same, but the change detection should be much more accurate.
A summery list of new features:
Memory Limit
Hugos will, by default, set aside a quarter of the total system memory, but you can set it via the OS environment variable
HUGO_MEMORYLIMIT
(in gigabytes). This is backed by a partitioned LRU cache used throughout Hugo. A cache that gets dynamically resized in low memory situations, allowing Go's Garbage Collector to free the memory.Dependency Tracker
Hugo has had a rule based coarse grained approach to server rebuilds that has worked mostly pretty well, but there have been some surprises (e.g. stale content). This is now revamped with a new dependency tracker that can quickly calculate the delta given a changed resource (e.g. a content file, template, JS file etc.). This handles transitive relations, e.g.
$page -> js.Build -> JS import
, or$page1.Content -> render hook -> site.GetPage -> $page2.Title
, or$page1.Content -> shortcode -> partial -> site.RegularPages -> $page2.Content -> shortcode ...
, and should also handle changes to aggregated values (e.g.site.Lastmod
) effectively.This covers all of Hugo's API with 2 known exceptions (a list that may not be fully exaustive):
Page
) passed in the template context to lang.Translate may not be detected correctly. We recommend having simple i18n templates without too much data context passed in other than simple types such as strings and numbers.Document Store
Previously we, a little simplified, split the document store (where we store pages and resources) in a tree per language. This worked pretty well, but the structure made some operations harder than they needed to be. We have now restructured it into one Radix tree for all languages. Internally the language is considered to be a dimension of that tree, and the tree can be viewed in all dimensions concurrently. This makes some operations re. language simpler (e.g. finding translations is just a slice range), but the idea is that it should also be relatively inexpensive to add more dimensions if needed (e.g. role).
Fixes
Fixes #10104
Fixes #10380
Fixes #10694
Fixes #11439
Fixes #11453
Fixes #11457
Fixes #11466
Fixes #11540
Fixes #11551
Fixes #11556
Fixes #11654
Fixes #11661
Fixes #11663
Fixes #11840
Fixes #11664
Fixes #11669
Fixes #11671
Fixes #11807
Fixes #11808
Fixes #11809
Fixes #11815
Fixes #7425
Fixes #7436
Fixes #7437
Fixes #7544
Fixes #7882
Fixes #8307
Fixes #8498
Fixes #8927
Fixes #9192
Fixes #9324
Fixes #9343