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

Make Codebase object thread-safe #3195

Merged
merged 4 commits into from Jul 7, 2022

Conversation

mitchellwrosen
Copy link
Member

Overview

This PR makes the Codebase object thread-safe by making each operation use a new underlying connection to SQLite, rather than a shared connection that the Codebase closes over.

Fixes #3190, which was caused by the local UI and ucm simultaneously using the same SQLite connection.


runTransaction :: Sqlite.Transaction a -> m a
runTransaction action =
withConn \conn -> Sqlite.runTransaction conn action
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm sure it's fine, but is it possible that using a single connection shared across the codebase gave us any benefits in terms of in-memory caching?

If there's anywhere we're querying the codebase in a tight-loop (there's probably at least some spots that do this) we're now acquiring a new connection for each and every query rather than using a single one.

I have no idea whether this is likely to actually cause problems in reality though 🤷🏼‍♂️

Copy link
Member Author

Choose a reason for hiding this comment

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

I do think it'd be wiser to reuse connections wherever possible - @tstat suggested we just use a connection pool. In the meantime, I'm not sure about where we might be hitting these functions in a tight loop - I did time loading the root branch of full-history base into memory, and there wasn't any noticeable slowdown. Push/pull to Share, at least, aren't using this Codebase interface for storing terms, so we don't have a blowup of connection creation/destruction over there.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I thought about a pool but wasn't sure whether it makes sense or not given how much lighter-weight sqlite connections are. Wouldn't hurt though, and probably would be easy to wire into what you've got here right?

If it's not showing any noticeable difference maybe it's fine?

Copy link
Contributor

@ChrisPenner ChrisPenner left a comment

Choose a reason for hiding this comment

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

Nice, I'll also need this for LSP work 🙌🏼

Just had the one question about whether we'll be sacrificing any performance by not sharing a long-lived connection in the codebase.

@mitchellwrosen mitchellwrosen merged commit 9e3faac into trunk Jul 7, 2022
@mitchellwrosen mitchellwrosen deleted the 22-07-05-local-ui-different-connections branch July 7, 2022 18:47
@ChrisPenner ChrisPenner mentioned this pull request Jul 8, 2022
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.

Codebase Server throws 500 occasionally when using the list api with a relativeTo
2 participants