Repository navigation
Fix region threading with MapItemSavedData - #538
Closed
NanaChiyo0721 wants to merge 1 commit into
Closed
NanaChiyo0721 wants to merge 1 commit into
NanaChiyo0721 wants to merge 1 commit into
Conversation
Member
|
This looks like it might work but it's not really the best solution. I'm working on a patch and will open a new PR soon. |
jpenilla
added a commit
that referenced
this pull request
Nov 19, 2026
* Rework map holder tracking to avoid cross-region access Vanilla updates every holder of a map from each holder's tick, reading other players' inventories, positions and equipment, which in Folia may be owned by other regions. Holders also remove each other, so frame viewers are constantly dropped and re-added and receive the full map again on every frame update. A player is now a holder of a map while the map is in their inventory or equipment, or while a frame showing it is tracking them, and only ever updates their own holder entry: - Carrying is detected from the map being ticked from the player's inventory/equipment; maps that were not ticked are removed at the end of the player's tick, which also replaces Paper's drop hook - Frame viewers are subscribed when they start tracking the frame and are sent the map immediately; they stay subscribed until tracking stops or the frame's map changes, so they no longer get full resends - Map invisibility equipment hides the player's marker per viewer, the wearer still sees themselves - Players keep a set of their maps, so leaving the world no longer scans every loaded map For a map with N carriers and V frame viewers, approximately: - Carrier ticks: O(N^2) inventory scans per tick -> O(N) - Frame updates: O(V * (N + V)) -> O(V), frame markers are updated once per frame instead of once per viewer - World leave: O(loaded maps) lock acquisitions -> O(player's maps) - Full map resends to frame viewers while the map is carried: up to one per viewer per frame update -> only on first subscription Each map lock is now held for constant work per holder instead of a loop over all holders, which greatly reduces contention between regions sharing a map, and no player ever waits on a map lock to update another player. Reported in #538 * Don't copy player markers to locked maps Player markers are live state maintained by each holder's tick, not part of the map's content. Copying them when locking is inconsistent: the copy is replaced as soon as that player holds the locked map, but stays at their lock-time position if they never do, where it also escapes map invisibility equipment and, once they are offline, vanish (canSee) filtering. Treat them as live state only, like on any other map. Frame and banner markers are still copied with the rest of the map's content. * Align map holder tracking with Paper PR Match the code from PaperMC/Paper#14499, so that once it is merged only the region threading parts remain in Folia: - Use the Paper PR's layout, comments and marker names (as Folia markers until it is merged) - Keep holders of spectators whose tick is skipped up to date - getHoldingPlayer throws instead of creating a holder * Restructure map changes as Paper feature patches Apply PaperMC/Paper#14499 (rework map holder tracking) and PaperMC/Paper#14500 (unload unused map data) as feature patches before Region Threading Base: - 0001: their file patch changes - 0002, 0003: their feature patches, unmodified Region Threading Base only adds the region threading changes on top, so once the Paper PRs are merged the first three patches can be dropped. Folia changes for unloading map data: - Unload unused maps before Folia's periodic map save - Remove SavedDataStorage#read, map data is now loaded through MapDataCache * Update Paper map patches Sync PaperMC/Paper#14500 review fixes: - Call MapInitializeEvent for new maps after registering them, and register them atomically, so listeners and other threads see the new map instead of looking it up on disk - Keep maps loaded again when a plugin removes a renderer - Make the saved data cache concurrent on Paper too; Region Threading Base keeps a diff on that line
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The hasMapInvisibilityItemEquipped was called in tickCarriedBy, might access another player's inventory without any async catcher and that player might not be on the same tick region of the ticking player