Skip to content

refactor: remove excessive goroutines in LoadMany - #128

Open
korotin wants to merge 1 commit into
graph-gophers:mainfrom
korotin:refactor/remove-excessive-goroutines-in-loadmany
Open

korotin wants to merge 1 commit into
graph-gophers:mainfrom
korotin:refactor/remove-excessive-goroutines-in-loadmany

Conversation

@korotin

@korotin korotin commented Sep 25, 2026

Copy link
Copy Markdown

LoadMany spawns a new goroutine per key, which may lead to excessive CPU and memory usage under heavy load.

Since LoadMany is just a wrapper around Load calls, and Load itself is guarded by two global locks (batchLock and cacheLock), the goroutines don't seem to buy us anything here and, as far as I can tell, can be removed entirely with no functional drawbacks.

In my PR I've refactored LoadMany to get rid of those goroutines.

I believe the change is backwards compatible, but there's one small detail worth mentioning: LoadMany used to call thunk() itself, which is no longer the case — this makes LoadMany lazy, just like Load already is. I'd expect this to be a minor change that shouldn't break anything, but please let me know if I'm missing a case here.

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.

1 participant