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

[performance] overhaul struct (+ result) caching library for simplicity, performance and multiple-result lookups #2535

Conversation

NyaaaWhatsUpDoc
Copy link
Member

@NyaaaWhatsUpDoc NyaaaWhatsUpDoc commented Jan 15, 2024

Description

  • updates gotosocial to use codeberg.org/gruf/go-structr instead of codeberg.org/gruf/go-cache/v3/result for result / struct caching which includes the following changes:
    • rewrite caching library for reduced complexity
    • improved caching library code commenting, design
    • now uses just a doubly linked list for tracking entries, instead a linked list + hashmap unnecessarily
    • uses linked lists is more places where advantageous over slices
    • increases the number of internal types that can be pooled / reused
    • adds much more robust tests
    • adds support for loading + caching multiple values at a time
  • updates gotosocial to use the new multi value cache loader functions to reduce database calls
  • removes the unnecessary step of making the sub-caches package private and only accessible by helper methods
  • updates regular cache sweep to keep caches within "60" threshold instead of "80" to give us more headroom during load spikes

Checklist

Please put an x inside each checkbox to indicate that you've read and followed it: [ ] -> [x]

If this is a documentation change, only the first checkbox must be filled (you can delete the others if you want).

  • I/we have read the GoToSocial contribution guidelines.
  • I/we have discussed the proposed changes already, either in an issue on the repository, or in the Matrix chat.
  • I/we have performed a self-review of added code.
  • I/we have written code that is legible and maintainable by others.
  • I/we have commented the added code, particularly in hard-to-understand areas.
  • I/we have made any necessary changes to documentation.
  • I/we have added tests that cover new code.
  • I/we have run tests and they pass locally with the changes.
  • I/we have run go fmt ./... and golangci-lint run.

@NyaaaWhatsUpDoc
Copy link
Member Author

this diff is a lot more intimidating than it looks in terms of actual gotosocial code, because it includes dropping the old result library from vendor/, and adding the new one.

the separate library itself can be found at https://codeberg.org/gruf/go-structr

@NyaaaWhatsUpDoc NyaaaWhatsUpDoc force-pushed the performance/cache-library-overhaul branch from d8d424c to 316c578 Compare January 15, 2024 20:59
@NyaaaWhatsUpDoc
Copy link
Member Author

the cache size estimator i'm going to do in a separate PR, this PR is already large enough, and enough of the internals are similar that the size estimations won't actually be that far off

@NyaaaWhatsUpDoc NyaaaWhatsUpDoc marked this pull request as ready for review January 16, 2024 12:37
internal/cache/db.go Outdated Show resolved Hide resolved
@NyaaaWhatsUpDoc NyaaaWhatsUpDoc force-pushed the performance/cache-library-overhaul branch from 0f4868c to 4c6dee1 Compare January 19, 2024 10:42
Copy link
Contributor

@tsmethurst tsmethurst left a comment

Choose a reason for hiding this comment

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

Good job kimbe 👍

@NyaaaWhatsUpDoc NyaaaWhatsUpDoc merged commit 7ec1e13 into superseriousbusiness:main Jan 19, 2024
2 checks passed
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