[codex] Optimize liquid flow scheduling#192
Draft
boybook wants to merge 1 commit into
Draft
Conversation
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.
背景
本轮优化来自高空并排水源/收起水源后的压测与多份 JFR 对比。测试中发现:当大量流动水在同一平面高度同步消退时,TPS 会突然下降;早期热点集中在液体
setBlock -> updateAround -> normalUpdate -> scheduleUpdate的普通更新放大,后续削减后,热点进一步转移到同一 tick 内大量 scheduled liquid update 集中执行,以及每个液体更新带来的Blockclone、事件、发包和调度器维护成本。这个 PR 把相关优化全部做成 Level/global 级可控实验特性,默认关闭,避免影响普通生产世界;小游戏(例如 BedWars)可以按 Level 灰度启用并随时回撤。
主要改动
LevelOptimizationSettings,作为 Level 级优化配置入口,避免在Level上散落多个 bool。nukkit.yml读取全局默认液体优化配置,新 Level 初始化时复制一份配置,插件仍可按 Level 覆盖。BlockUpdateScheduler等价优化索引:equivalentOptimizationEnabled=true时启用位置 + block id 的 primitive 去重索引;contains()扫描所有 tick bucket 的成本;removeAll。BlockLiquid等价降分配:Blockclone;tickRate()、decay、事件和setBlock(update=true)语义。normalUpdateDeduplicationEnabled:同 tick 内 normal update 按坐标去重;liquidUpdateAroundSuppressionEnabled:液体变化时抑制完整 6 邻域普通更新,但仍唤醒相邻液体,避免收水后水完全不更新;maxLiquidNormalUpdatesPerTick:限制每 tick 液体 normal update;maxLiquidScheduledUpdatesPerTick:限制每 tick scheduled liquid update。maxLiquidScheduledUpdatesPerTick使用随机抽样,而不是固定执行队列前 N 个,避免同一平面水流出现固定一侧先动、另一侧长期停滞。行为与风险
equivalentOptimizationEnabled仍用于严格等价优化,不承载跳过事件/跳过更新之类非等价行为。normalUpdateDeduplicationEnabled、liquidUpdateAroundSuppressionEnabled、maxLiquidNormalUpdatesPerTick、maxLiquidScheduledUpdatesPerTick都属于实验特性,可能改变极端水流场景的演化节奏。验证
./gradlew :Nukkit:compileJava :ECBedWars:compileJavagit -C /Users/fangyizhou/Documents/coding/CodeFunCore/Nukkit diff --checkgit -C /Users/fangyizhou/Documents/coding/CodeFunCore/Nukkit/src/main/resources/lang diff --checkgit -C /Users/fangyizhou/Documents/coding/CodeFunCore diff --check -- ECBedWars/src/main/java/net/easecation/ecbedwars/stage/BedWarsStage.java./gradlew :Nukkit:shadowJar_simple/nukkit.jarSHA256:65404666c94923541082e20cd1fba20b56a1bf33cc417c4a77d3cfc921509006