This repository was archived by the owner on Jul 9, 2026. It is now read-only.
Thread-safe block and item type ID assignment - #7045
Open
dktapps wants to merge 2 commits into
Open
Conversation
I realised the PR #6786 was trying too hard to avoid sharing any data between threads, but it looks like the performance impact of trying to do so is much greater than the performance impact of just sharing ID registration tables. A new method of claiming type IDs has been implemented. Using a string unique to the block type, such as the block's Minecraft string ID, blocks can ensure they always get to claim the same ID on all threads. This ID is not guaranteed to be the same across different runs, but it at least permits moving block and item type/state IDs across threads without ridiculous serialization hacks. There may be other places where we could benefit from a system like this. Basically anywhere plugins might need to fight over ID assignment. Checks have also been added to ensure that plugins can't just use a random unassigned type ID, as this may cause conflicts with other plugins. This isn't foolproof, but we can't do better than this without breaking BC and stopping plugins from providing numeric type IDs entirely (thereby stopping them from being hardcoded).
in order to support cross-thread setInstance and reset, we'd have to synchronize with the shared globals on every access to ensure the instance hadn't been changed. This doesn't really make any sense.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
I realised the PR #6786 was trying too hard to avoid sharing any data between threads, but it looks like the performance impact of trying to do so is much greater than the performance impact of just sharing ID registration tables.
A new method of claiming type IDs has been implemented. Using a string unique to the block type, such as the block's Minecraft string ID, blocks can ensure they always get to claim the same ID on all threads. This ID is not guaranteed to be the same across different runs, but it at least permits moving block and item type/state IDs across threads without ridiculous serialization hacks.
There may be other places where we could benefit from a system like this. Basically anywhere plugins might need to fight over ID assignment.
Checks have also been added to ensure that plugins can't just use a random unassigned type ID, as this may cause conflicts with other plugins. This isn't foolproof, but we can't do better than this without breaking BC and stopping plugins from providing numeric type IDs entirely (thereby stopping them from being hardcoded).
Related issues & PRs
Changes
API changes
BlockTypeIds::claimId()andBlockTypeIds::getClaimant()ItemTypeIds::claimId()andItemTypeIds::getClaimant()BlockTypeIds::newId()andItemTypeIds::newId()ThreadSafeSingletonTraitBehavioural changes
Unless plugins use these new APIs, none are expected, bar some deprecation notices.
Follow-up
BlockIdentifierandItemIdentifierto accept strings directly instead of ints (and have numeric type IDs internally claimed)Tests
tests are green