Skip to content

Conversation

@ormsbee
Copy link
Contributor

@ormsbee ormsbee commented Jan 7, 2026

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:

def some_fn(foo, bar, store=None):
    store = store or modulestore()
    # rest of function

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.

@ormsbee ormsbee force-pushed the remove-global-modulestore branch from aabfa8a to f3090c7 Compare January 7, 2026 05:12
@ormsbee ormsbee marked this pull request as draft January 7, 2026 06:57
@ormsbee ormsbee changed the title refactor: remove modulestore global WIP: refactor: remove modulestore global Jan 7, 2026
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