Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unnecessary map data saves (#12295) #12296

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Dqu1J
Copy link
Contributor

@Dqu1J Dqu1J commented Mar 14, 2025

Fixes #12295

Currently, MapCanvas API unnecessarily causes map data file to save.

The API calls this.mapView.worldMap.setColorsDirty() to mark colors dirty for players, however this has the side-effect of saving the map .dat files as well:

public void setColorsDirty(int x, int z) {
    this.setDirty(); // This saves the data file! 

    for (MapItemSavedData.HoldingPlayer holdingPlayer : this.carriedBy) {
        holdingPlayer.markColorsDirty(x, z); // This is what the API wants to do!
    }
}

This causes unnecessary lag during world saves, which scales with the amount of maps handled with API since last save. On servers that heavily rely on imageonmap-like plugins, it can cause lag spikes of dozens of seconds.

This PR changes this method to add a boolean argument to the method that determines whether the file is saved or not, which is used by the API. An overload is added for compatibility, and for vanilla.

@Dqu1J Dqu1J requested a review from a team as a code owner March 14, 2025 13:15
@@ -64,7 +64,7 @@ public void setPixel(int x, int y, byte color) {
return;
if (this.buffer[y * 128 + x] != color) {
this.buffer[y * 128 + x] = color;
this.mapView.worldMap.setColorsDirty(x, y);
this.mapView.worldMap.setColorsDirty(x, y, false); // Paper - Fix unnecessary map data saves
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it really safe to never save the data after any changes where done here?
I mean wouldn't that break the expectations of current plugins?
And if yes, maybe pulling up a "doNotSave" optional parameter into the API?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@FireInstall custom renderers never end up saving data to .dat files afaik
quoting what Warriorrrr told me on discord, "drawing the image only modifies the buffer inside the craft canvas and not the underlying colors array the game saves"

Copy link
Contributor

@FireInstall FireInstall Mar 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alright, if not only drawing but also chaning pixels should not save, then thanks!
In that case this can get marked as resolved. Have a nice day ~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Awaiting review
Development

Successfully merging this pull request may close these issues.

MapCanvas#drawImage unnecessarily causes map data file to save
3 participants