Skip to content
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

Cache DisplaySourceSet as it's stored a lot inside of ContentPages #4008

Merged
merged 5 commits into from
Jan 30, 2025

Conversation

whyoleg
Copy link
Collaborator

@whyoleg whyoleg commented Jan 27, 2025

Found and tested on https://github.com/rjaros/kilua (results are reproducible even after several runs).

Before:
image

After:
image

Three were three CPU peaks:

  • model generation (analysis)
  • model conversion (Documentable -> Content) - highlighted point, the peak is absent after optimization
  • HTML rendering

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.

@whyoleg whyoleg requested a review from vmishenev January 27, 2025 13:18
@whyoleg whyoleg self-assigned this Jan 27, 2025
…okka pipeline execution, as if we stop at verification stage we should not proceed with execution
@whyoleg whyoleg merged commit 70beb15 into master Jan 30, 2025
14 checks passed
@whyoleg whyoleg deleted the whyoleg/perf-displaySourceSet branch January 30, 2025 14:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants