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

Integrate LazyDFU into Sponge proper #3567

Merged
merged 1 commit into from
Dec 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,18 @@ public final class OptimizationCategory {
"are `persistent`. Does not drastically improve performance.")
public boolean disableScheduledUpdatesForPersistentLeafBlocks = true;

@Setting("enable-lazydfu")
@Comment("By default, Vanilla 'warms-up' all migration rules for\n"
+ "every Minecraft version when the game starts. This often\n"
+ "causes a period of extremely high CPU usage when the game\n"
+ "starts, often for no benefit since the typical pattern is\n"
+ "that most chunks do not have to be migrated, or only have\n"
+ "to be migrated from just a few versions. This option disables\n"
+ "migration rules from being 'warmed-up' and instead forces them\n"
+ "to be generated on demand. This is a very safe optimization and\n"
+ "should usually remain enabled.")
public boolean enableLazyDFU = true;

public OptimizationCategory() {
// Enabled by default on SpongeVanilla, disabled by default on SpongeForge.
// Because of how early this constructor gets called, we can't use SpongeImplHooks or even Game
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* This file is part of Sponge, licensed under the MIT License (MIT).
*
* Copyright (c) SpongePowered <https://www.spongepowered.org>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.common.util;

import com.mojang.datafixers.DataFixer;
import com.mojang.datafixers.DataFixerBuilder;
import java.util.concurrent.Executor;

/**
* This version of {@code DataFixerBuilder} does not immediately initialize rules.
*/
public class LazyDataFixerBuilder extends DataFixerBuilder {

private static final Executor NO_OP_EXECUTOR = command -> {};

public LazyDataFixerBuilder(int dataVersion) {
super(dataVersion);
}

@Override
public DataFixer build(Executor executor) {
return super.build(NO_OP_EXECUTOR);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* This file is part of Sponge, licensed under the MIT License (MIT).
*
* Copyright (c) SpongePowered <https://www.spongepowered.org>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.common.mixin.optimization.general;

import com.mojang.datafixers.DataFixerBuilder;
import net.minecraft.util.datafix.DataFixers;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.common.util.LazyDataFixerBuilder;

@Mixin(DataFixers.class)
public abstract class DataFixersMixin_Optimization_LazyDFU {

// Replaces Mojang's default DataFixerBuilder with a version that doesn't prebake all version rules at server
// startup.
@Redirect(method = "createFixerUpper", at = @At(value = "NEW", target = "com/mojang/datafixers/DataFixerBuilder"))
private static DataFixerBuilder createFixerUpper$replaceBuilder(int dataVersion) {
return new LazyDataFixerBuilder(dataVersion);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public boolean shouldApplyMixin(final String targetClassName, final String mixin

// So that any additional optimizations can be added in succession.
private static final Map<String, Function<OptimizationCategory, Boolean>> mixinEnabledMappings = ImmutableMap.<String, Function<OptimizationCategory, Boolean>> builder()
.put("org.spongepowered.common.mixin.optimization.general.DataFixersMixin_Optimization_LazyDFU", optimizationCategory -> optimizationCategory.enableLazyDFU)
.put("org.spongepowered.common.mixin.optimization.entity.EntityMixin_Optimization_Collision", optimizationCategory -> optimizationCategory.useActiveChunksForCollisions)
.put("org.spongepowered.common.mixin.optimization.world.entity.TamableAnimalMixin_Optimization_Owner", optimizationCategory -> optimizationCategory.cacheTameableOwners)
// TODO investigate what is still relevant and add them back
Expand Down
1 change: 1 addition & 0 deletions src/mixins/resources/mixins.sponge.optimization.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"package": "org.spongepowered.common.mixin.optimization",
"plugin": "org.spongepowered.common.mixin.plugin.OptimizationPlugin",
"mixins": [
"general.DataFixersMixin_Optimization_LazyDFU",
"entity.EntityMixin_Optimization_Collision",
"world.entity.TamableAnimalMixin_Optimization_Owner"
]
Expand Down