Skip to content

Make CommandStorage namespaces a ConcurrentHashMap - #514

Closed
lewisgibson wants to merge 2 commits into
PaperMC:ver/26.2.xfrom
lewisgibson:command-storage-chm
Closed

lewisgibson wants to merge 2 commits into
PaperMC:ver/26.2.xfrom
lewisgibson:command-storage-chm

Conversation

@lewisgibson

@lewisgibson lewisgibson commented Oct 1, 2026 •

Copy link
Copy Markdown

CommandStorage lazily loads a namespace's container into a plain HashMap the first time it is read. Loot tables with a storage nbt or number provider and text components with a storage source read it from whichever region is running them, so two regions reading a namespace for the first time at once race on the put. This makes the map a ConcurrentHashMap, like the saved data storage cache it loads from, and folds the change into the Region Threading Base patch.

Tested on ver/26.2.x with a small test plugin that starts 8 threads at once, each calling CommandStorage#set for 5000 distinct namespaces (40000 in total), then counts keys(). It uses set because that is the quickest way to put many namespaces into the map from many threads, and it is the same map and the same unsynchronised put. On the unpatched build 202 of the 40000 entries were lost to the race, with this change none were.

This was done with AI (Claude Opus 5.5 and GPT Astra, high effort). I've reviewed it and tested it myself.

CommandStorage lazily fills a plain HashMap of namespace containers from whichever region reads it first. See the patch for details.
@lewisgibson lewisgibson closed this Oct 2, 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