Cache DisplaySourceSet
as it's stored a lot inside of ContentPage
s
#4008
+63
−37
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.
Found and tested on https://github.com/rjaros/kilua (results are reproducible even after several runs).
Before:
After:
Three were three CPU peaks:
Max memory usage: 7600 -> 5800 MB
Memory usage after model conversion: 6500 -> 3500 MB
Execution time is roughly the same.
Reasoning:
Every ContentNode contains a set of DisplaySourceSet which is an object with rather big footprint and initialization cost (to be specific CompositeSourceSetID). Overall, amount of distinct source sets during documentation generation is fixed so we could pre-compute those. But because the usages of those types are sparred along the codebase, it's better to just add a cache in place of conversion.
Additionally, the cache was added for a case where we perform conversion on multiple source sets. This is because in most of the places where we need this conversion we will use the same set of source sets.
P.S. I've also checked kotlinx.coroutines and kotlinx.io core modules, but I haven't found significant difference - after optimization it uses ±50-100 MB less memory, which could be just an error. So most likely only bigger projects are affected.