WIP: refactor: remove modulestore global #37842
Draft
+69
−77
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Let's see how much stuff breaks if we just remove the cache modulestore global.
This could introduce a performance regression if it's called many times (it looks like it takes something like 1-2 ms per invocation). If it is a problem, request-level caching may be enough to take care of it.
Holding onto global modulestore references has long been a source of memory leaks and gives us many opportunities to shoot ourselves in the foot when dealing with multiple threads and potential cross-contamination of the shared object across multiple users. This could remove a whole class of bugs if it works. Of course, it could also break things in unanticipated ways.
There are a bunch of places where we call
modulestore()repeatedly in the same function instead of assigning to a variable, on the assumption that it's a singleton. We would want to clean that up. It might involve passing the modulestore as an optional argument in a bunch of places, so we stop recreating it so casually, like:The risk is performance regression from calling modulestore init functions many times.
It's also possible that we can make modulestore init even cheaper than it is today.