Skip to content

refactor: simplify caches #448

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

Merged
merged 14 commits into from
Jul 12, 2025
Merged

refactor: simplify caches #448

merged 14 commits into from
Jul 12, 2025

Conversation

psteinroe
Copy link
Collaborator

@psteinroe psteinroe commented Jul 12, 2025

fixes unbounded memory caches that could lead to oom issues. Document-level caches would accumulate indefinitely as users edited files.

replaced all DashMap usages with appropriate data structures based on access patterns:
Bounded Memory Caches (LRU):

  • PgQueryStore: DashMap → Mutex<LruCache<1000>> - AST parsing cache
  • TreeSitterStore: DashMap → Mutex<LruCache<1000>> - CST parsing cache
  • AnnotationStore: DashMap → Mutex<LruCache<1000>> - Statement annotations cache

Read-Heavy Workloads (RwLock):

  • SchemaCacheManager: DashMap → RwLock - Database schema cache
  • ConnectionManager: DashMap → RwLock - Database connection pool cache
  • WorkspaceServer.documents: DashMap → RwLock - Open document cache

@psteinroe psteinroe changed the title refactor: drop change.rs <3 refactor: simplify caches Jul 12, 2025
@psteinroe psteinroe marked this pull request as ready for review July 12, 2025 14:24
Copy link
Collaborator

@juleswritescode juleswritescode left a comment

Choose a reason for hiding this comment

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

Nice :)

Document-level caches would accumulate indefinitely as users edited files.

I'm curious, is this a bug with the lib? Or what happens there?

@psteinroe
Copy link
Collaborator Author

Nice :)

Document-level caches would accumulate indefinitely as users edited files.

I'm curious, is this a bug with the lib? Or what happens there?

this is just a follow-up of the change refactoring. before, we were removing data from the parse caches (pg_query, treesitter) based on the statement changed and statement deleted events that the change handling emitted. Without that, we never delete any parsing results. if a user now starts typing, we keep every parse result of every statement change. this pr fixes that with the LRU cache.

I then researched a bit about dash map and replaced it in other places with a more suitable store.

@psteinroe psteinroe changed the base branch from refactor/changes to main July 12, 2025 18:26
@psteinroe psteinroe changed the base branch from main to refactor/changes July 12, 2025 18:27
@psteinroe psteinroe changed the base branch from refactor/changes to main July 12, 2025 18:28
@psteinroe psteinroe changed the base branch from main to refactor/changes July 12, 2025 18:28
@psteinroe psteinroe changed the base branch from refactor/changes to main July 12, 2025 18:29
@psteinroe psteinroe merged commit c06ab00 into main Jul 12, 2025
7 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