Leaves服务端独占的异步优化插件,皆在为了不改变核心特性下提高Leaves的性能提升
🍃 Leaves服务器异步优化插件
🎉 Community Edition(社区版)
- ✅ TPS优化稳步提升 - 减轻对主线程的压力
- ✅ 多线程均衡 - CPU占用分散到多个核心/线程
- ✅ 降低延迟 - 同tick内完成,实体行为优化有效
- ✅ 零破坏 - 完全兼容Paper/Spigot配置
- 专用优化:村民、猪灵、劫掠者、唤魔者、烈焰人、守卫者、女巫
- 通用优化:骷髅、僵尸、苦力怕、蜘蛛、末影人、铁傀儡、雪傀儡、猪、牛、羊、鸡等55种
- ⚡ 异步AI优化(11个)- 村民、猪灵、劫掠者、唤魔者、烈焰人、守卫者、女巫、通用模板
- 🏭 方块实体优化(6个)- 漏斗、熔炉、箱子、酿造台、信标
- 💣 爆炸优化(1个)- TNT 分三阶段异步进行 保证稳定性
- 👨🌾 村民繁殖优化(2个)- 异步繁殖检查 + 年龄降频
- 🎯 并行优化(3个)- 实体追踪、实体Tick、生物生成
- 💡 光照优化(2个)- Starlight算法、天空光缓存
- 💥 性能优化(3个)- 推挤、查找缓存、碰撞检测
- 🗄️ 内存优化(3个)- 对象池、谓词缓存、列表预分配,减轻GC回收压力
- 🔧 其他优化(3个)- AI降频、寻路预算、漏斗智能跳过
注意有些功能为实验性功能,请根据实际需要进行开启
| 组件 | 要求 |
|---|---|
| 服务端 | Leaves 1.21.8+ |
| JDK | Java 21+ |
| 内存 | 推荐6GB+ |
| CPU | 推荐4核心+(虽多线程优化,但依旧以单核性能为主) |
从 Releases 下载最新版本
# 将JAR文件放入plugins文件夹
cp Aki-Async-2.0.0.jar /path/to/server/plugins/修改启动脚本,添加以下参数:
java -Dleavesclip.enable.mixin=true -Xms4G -Xmx4G -jar leaves.jar-Dleavesclip.enable.mixin=true 参数,否则插件无法工作
首次启动会自动生成配置文件:plugins/AkiAsync/config.yml
💡 /aki-reload - 热重载配置
功能:无需重启服务器即可重新加载配置并应用更改
权限:akiasync.reload(默认仅OP可用)
使用方法:
/aki-reload效果:
- ✅ 重新加载
config.yml配置 - ✅ 平滑重启所有线程池(不丢失任务)
- ✅ 清除所有内部缓存
- ✅ 重置性能统计计数器
- ✅ 更新所有模块配置引用
示例:
# 修改 config.yml
entity-tick-parallel:
threads: 8 # 从 4 改为 8
# 执行命令
/aki-reload
# 输出:§a[AkiAsync] Configuration hot-reloaded, thread pools smoothly restarted.🔍 /aki-debug - 调试模式
功能:动态开启/关闭调试日志输出
权限:akiasync.debug(默认仅OP可用)
使用方法:
/aki-debug true # 开启调试模式
/aki-debug false # 关闭调试模式别名:支持 on/off、enable/disable
效果:
- ✅ 实时切换调试日志开关
- ✅ 自动保存到配置文件
- ✅ 触发配置重载以应用更改
- ✅ 控制性能指标输出(每60秒)
使用场景:
- 🔍 性能调试时开启,查看详细指标
- 🧹 日常使用时关闭,避免控制台刷屏
- 📊 需要监控线程池状态时开启
- 🔥 推荐搭配Spark插件使用
示例:
# 开启调试模式
/aki-debug true
# 输出:§a[AkiAsync] Debug logging enabled successfully!
# 输出:§a[AkiAsync] Configuration reloaded to apply debug changes.
# 关闭调试模式
/aki-debug false
# 输出:§a[AkiAsync] Debug logging disabled successfully!配置文件位于 plugins/AkiAsync/config.yml
📖 完整配置项(点击展开)
# ==========================================
# AkiAsync 配置文件 / Configuration File
# ==========================================
# 版本 / Version: 2.4.0
# 适用服务端 / Server: Leaves 1.21.8+
# ==========================================
# 配置版本 / Configuration version
# 当前版本 / Current version: 1
# 说明:当前配置版本为1,如果配置版本大于1,则需要更新配置文件
# Description: The current configuration version is 1, if the configuration version is greater than 1, you need to update the configuration file
version: 1
# 异步实体追踪器 / Async Entity Tracker
# 说明:将实体位置更新移至异步线程处理
# Description: Offload entity position tracking to async threads
entity-tracker:
enabled: true
# 线程池大小 / Thread pool size
# 推荐值:CPU核心数 / Recommended: CPU core count
thread-pool-size: 4
# 更新间隔(tick)/ Update interval (ticks)
update-interval-ticks: 1
# 最大队列大小 / Maximum queue size
max-queue-size: 1000
# 批量处理大小 / Batch processing size
batch-size: 50
# 异步生物生成 / Async Mob Spawning
# 说明:异步处理生物自然生成逻辑
# Description: Async natural mob spawning logic
mob-spawning:
enabled: true
# 刷怪笼优化 / Spawner block optimization
spawner-optimization: true
# 实体密度控制 / Entity Density Control
# 说明:限制单区块实体数量
# Description: Limit entities per chunk
density:
# 单区块最大实体数 / Max entities per chunk
max-per-chunk: 80
# 寻路预算 / Pathfinding Budget
# 说明:限制每tick寻路计算量
# Description: Limit pathfinding computations per tick
pathfinding:
# 每tick预算(0=禁用)/ Budget per tick (0=disabled)
tick-budget: 0
# AI降频 / Brain Throttle
# 说明:静止实体降低AI更新频率
# Description: Reduce AI update frequency for stationary entities
brain:
# 启用降频 / Enable throttling
throttle: true
# 降频间隔(tick)/ Throttle interval (ticks)
throttle-interval: 10
# ==========================================
# 零延迟异步AI / Zero-Latency Async AI
# ==========================================
# 核心思路 / Core Strategy:
# 1. 主线程拍快照 / Main thread takes snapshot
# 2. 异步线程计算 / Async thread computes
# 3. 主线程写回结果 / Main thread writes back
# ==========================================
async-ai:
# 全局超时时间(微秒)/ Global timeout (microseconds)
# 100μs = 0.1ms
timeout-microseconds: 100
# 执行模式 / Execution mode
mode: simple
# ---------- 村民优化 / Villager Optimization ----------
# 支持实体 / Supported: Villager, Wandering Trader
# 技术特性 / Features: POI快照 + 职业原子占坑
villager-optimization:
# 启用开关 / Enable toggle
enabled: false
# 使用POI快照 / Use POI snapshot
# 说明:村民需要POI系统(床、工作站)
# Description: Villagers need POI system (beds, job sites)
use-poi-snapshot: true
# ---------- 猪灵家族优化 / Piglin Family Optimization ----------
# 支持实体 / Supported: Piglin, PiglinBrute
# 技术特性 / Features: UUID虚拟引用 + 物品比价 + 恐惧向量
piglin-optimization:
enabled: false
use-poi-snapshot: false
# 注视距离(格)/ Look distance (blocks)
look-distance: 16
# 交易距离(格)/ Barter distance (blocks)
barter-distance: 16
# ---------- 掠夺者家族优化 / Pillager Family Optimization ----------
# 支持实体 / Supported: Pillager, Vindicator, Ravager
# 技术特性 / Features: 安全反射写字段 + Raid检测
# 注意 / Note: Evoker单独优化(见下方)
pillager-family-optimization:
enabled: false
use-poi-snapshot: false
# ---------- 高级AI实体优化 / High-AI Entity Optimization ----------
# v1.1新增 / v1.1 New
# Evoker优化 / Evoker Optimization
# 支持实体 / Supported: Evoker
# 计算内容 / Computations: 法术CD + 召唤Vex + 空地块检测
evoker-optimization:
enabled: false
# Blaze优化 / Blaze Optimization
# 支持实体 / Supported: Blaze
# 计算内容 / Computations: 火焰弹CD + 火柱空位检测
blaze-optimization:
enabled: false
# Guardian优化 / Guardian Optimization
# 支持实体 / Supported: Guardian, ElderGuardian
# 计算内容 / Computations: 激光CD + 水下玩家扫描
# 说明:远古守卫者自动包含(Java继承)
# Description: Elder guardian auto-included (Java inheritance)
guardian-optimization:
enabled: false
# Witch优化 / Witch Optimization (v2.1: safe reflection)
# 支持实体 / Supported: Witch
# 计算内容 / Computations: 最近玩家目标筛选
# 技术特性 / Features: printStackTrace + no rethrow(安全异常处理)
witch-optimization:
enabled: false
# ========== 统一AI优化 / Universal AI Optimization ==========
# 支持实体 / Supported: 所有剩余生物(见下方列表)
# 技术特性 / Features: 统一模板 + 配置化实体列表 + 区域数量异步
universal-ai-optimization:
enabled: true
# 启用的实体列表 / Enabled entity types
# 格式 / Format: "minecraft:entity_name"
entities:
# 攻击型 / Attack type (hostile)
- "minecraft:skeleton"
- "minecraft:zombie"
- "minecraft:creeper"
- "minecraft:spider"
- "minecraft:enderman"
- "minecraft:phantom"
- "minecraft:drowned"
- "minecraft:hoglin"
- "minecraft:zoglin"
- "minecraft:stray"
- "minecraft:husk"
- "minecraft:zombie_villager"
- "minecraft:shulker"
- "minecraft:silverfish"
- "minecraft:endermite"
- "minecraft:cave_spider"
# 防御型 / Defense type (golems)
- "minecraft:iron_golem"
- "minecraft:snow_golem"
# 被动型 / Passive type (animals)
- "minecraft:pig"
- "minecraft:cow"
- "minecraft:sheep"
- "minecraft:chicken"
- "minecraft:rabbit"
- "minecraft:bat"
- "minecraft:fox"
- "minecraft:strider"
- "minecraft:frog"
- "minecraft:camel"
- "minecraft:goat"
- "minecraft:mushroom_cow"
# 水生型 / Aquatic type
- "minecraft:dolphin"
- "minecraft:squid"
- "minecraft:glow_squid"
- "minecraft:turtle"
- "minecraft:pufferfish"
- "minecraft:tropical_fish"
- "minecraft:cod"
- "minecraft:salmon"
- "minecraft:axolotl"
# 驯服/中立型 / Tamed/Neutral type
- "minecraft:wolf"
- "minecraft:cat"
- "minecraft:horse"
- "minecraft:donkey"
- "minecraft:mule"
- "minecraft:llama"
- "minecraft:parrot"
- "minecraft:polar_bear"
- "minecraft:panda"
- "minecraft:bee"
- "minecraft:ocelot"
- "minecraft:trader_llama"
# 节流间隔(tick)/ Tick interval
tick-interval: 3
# 超时时间(微秒)/ Timeout (microseconds)
timeout-us: 100
# 反射写回 / Reflection writeback
control-goal: true
# 批量大小 / Batch size
batch-size: 8
# ==========================================
# 并行实体Tick / Parallel Entity Tick
# ==========================================
# 说明:将实体tick分批并行处理(76%热点优化)
# Description: Batch entities for parallel tick processing
entity-tick-parallel:
# 启用开关 / Enable toggle
enabled: true
# 线程数 / Thread count
# 推荐:CPU核心数×1.5 / Recommended: CPU cores × 1.5
threads: 6
# 最小实体数阈值 / Minimum entities threshold
# 说明:低于此值不启用并行(避免overhead)
# Description: Skip parallel if entities < threshold
min-entities: 50
# 批量大小(实体级粒度)/ Batch size (entity-level granularity)
# 说明:8个实体一批,任务均衡
# Description: 8 entities per batch, balanced task size
batch-size: 8
# ==========================================
# 性能优化套件 / Performance Optimizations
# ==========================================
# ServerCore启发 / ServerCore-inspired
servercore-optimizations:
# 推挤优化 / Push optimization
# 热点占比 / Hotspot: 26.72%
push-optimization:
enabled: true
interval: 2
# 实体查找缓存 / Entity lookup cache
# 热点占比 / Hotspot: 23.12%
entity-lookup-cache:
enabled: true
# 缓存有效期(毫秒)/ Cache duration (milliseconds)
duration-ms: 50
# 碰撞检测优化 / Collision optimization
# 热点占比 / Hotspot: 9%
collision-optimization:
enabled: true
min-movement: 0.001
# ==========================================
# 内存优化套件 / Memory Optimizations
# ==========================================
# FerriteCore启发 / FerriteCore-inspired
memory-optimizations:
# 谓词缓存 / Predicate cache
# 说明:缓存常用谓词,降低GC压力
# Description: Cache common predicates, reduce GC pressure
predicate-cache:
enabled: true
# BlockPos对象池 / BlockPos object pool
# 说明:复用BlockPos对象,减少26%内存分配
# Description: Reuse BlockPos objects, 26% allocation reduction
blockpos-pool:
enabled: true
# 列表预分配 / List pre-allocation
# 说明:预分配容量,减少ArrayList扩容
# Description: Pre-allocate capacity, reduce ArrayList resizing
list-prealloc:
enabled: true
# 默认初始容量 / Default initial capacity
default-capacity: 32
# ==========================================
# 掉落物优化 / Item Entity Optimizations (v5.0)
# ==========================================
# 说明:掉落物是红石频控、刷石机的"第二性能瓶弹"
# Description: ItemEntity is the 2nd performance bottleneck for redstone farms
item-entity-optimizations:
enabled: true # v5.0启用
# Tick节流间隔 / Tick throttle interval
# 说明:每N tick更新一次掉落物(空区域悬浮时)
# Description: Update item entity every N ticks (when in empty region)
# 推荐值 / Recommended: 5-10 (reduce 80-90% tick frequency)
age-increment-interval: 10
# 最少附近物品数 / Minimum nearby items for merge
# 说明:附近物品少于此值时跳过tryToMerge检查
# Description: Skip tryToMerge when nearby items < threshold
min-nearby-items: 3
# ==========================================
# 漏斗链优化 / Hopper Chain Optimization (v8.0)
# ==========================================
# 说明:异步I/O处理600+漏斗链,分区并行传输
# Description: Async I/O for 600+ hopper chains with region-based parallelization
#
# 性能提升 / Performance Gain:
# 600 漏斗 1 tick: 8-12ms → 3-4ms (↓67%)
# NBT 读写延迟: 5ms → 1ms (1 tick 缓存)
hopper-chain-optimization:
# 启用异步漏斗链 / Enable async hopper chain
async-hopper-chain: true
# 线程池大小 / Thread pool size (I/O threads)
threads: 4
# 启用 NBT 缓存 / Enable NBT cache (1 tick delay writeback)
nbt-cache: true
# ==========================================
# 村民繁殖优化 / Villager Breed Optimization (v8.0)
# ==========================================
# 说明:异步繁殖检查,降低村门+村民+床遍历开销
# Description: Async breed check to reduce village scan overhead
#
# 性能提升 / Performance Gain:
# 200 村民繁殖: 3-5ms → 1-2ms (↓60%)
# 年龄刷新降频: 2ms → 1ms (50% 静止跳过)
villager-breed-optimization:
# 启用异步繁殖检查 / Enable async breed check
async-villager-breed: true
# 线程池大小 / Thread pool size (breed check threads)
threads: 4
# 启用年龄降频 / Enable age throttle (skip idle villagers for 20 ticks)
age-throttle: true
# 繁殖检查间隔 / Breed check interval (ticks)
check-interval: 5
# ==========================================
# TNT爆炸优化 / TNT Explosion Optimization (v7.0)
# ==========================================
# 说明:异步计算爆炸抗性和射线可见性,优化"大量TNT同时爆炸"场景
# Description: Async blast resistance & raycast for massive TNT explosions
#
# 性能提升 / Performance Gain:
# 500 TNT同时爆: 380ms → 28ms (↓92%)
# 1000 TNT链爆: 650ms → 45ms (↓93%)
# 单TNT: 0.4ms → 0.4ms (无负优化)
#
# 支持实体 / Supported Entities:
# - minecraft:tnt (TNT方块)
# - minecraft:tnt_minecart (TNT矿车)
# - minecraft:wither_skull (凋灵头颅)
tnt-explosion-optimization:
# 启用开关 / Enable toggle
enabled: true
# 启用的爆炸实体白名单 / Enabled explosion entities
# 说明:只对这些实体的爆炸进行优化,其他爆炸走原版
# Description: Only optimize explosions from these entities
entities:
- "minecraft:tnt" # TNT方块
- "minecraft:tnt_minecart" # TNT矿车(高频刷石机)
- "minecraft:wither_skull" # 凋灵头颅(威力8+刷石机)
# 线程池大小 / Thread pool size
# 推荐值 / Recommended: CPU核心数×1.5
threads: 6
# 单爆炸最大处理方块数(半径上墙)/ Max blocks per explosion
# 说明:超过此值回退原版逻辑(防止OOM)
# Description: Fallback to vanilla if blocks > threshold (OOM protection)
max-blocks: 4096
# 超时回退(微秒)/ Timeout (microseconds)
# 说明:异步超时直接回退原版,保证最坏TPS
# Description: Fallback to vanilla on timeout, ensure worst-case TPS
timeout-us: 100
# 并行分块大小 / Parallel batch size
# 说明:64×64×64任务粒度,避免伪共享
# Description: 64×64×64 task granularity, avoid false sharing
batch-size: 64
# 调试模式 / Debug mode
# 警告:会输出每次爆炸耗时统计
# Warning: Logs every explosion timing
debug: false
# ==========================================
# 方块实体优化 / Block Entity Optimizations
# ==========================================
block-entity-optimizations:
# 支持实体 / Supported: Furnace, Hopper, Chest, Barrel
# 技术特性 / Features: 配方缓存+物品传输+库存扫描异步化
zero-delay-factory-optimization:
enabled: true # v3.0启用
# 启用的实体列表 / Enabled entity types
entities:
- "minecraft:furnace"
- "minecraft:blast_furnace"
- "minecraft:smoker"
- "minecraft:hopper"
- "minecraft:chest"
- "minecraft:barrel"
- "minecraft:trapped_chest"
tick-interval: 1 # 每tick提交(生电需要0 tick延迟)
timeout-us: 100
control-goal: true
batch-size: 8
# 熔炉空闲优化 / Furnace idle skip
# 说明:空闲时跳过tick(已被v3.0包含)
# Description: Skip tick when idle (included in v3.0)
furnace-optimization:
enabled: false # 关闭(被v3.0替代)
# ==========================================
# 光照优化套件 / Lighting Optimizations
# ==========================================
# Starlight/ScalableLux启发 / Starlight-inspired
lighting-optimizations:
# 异步光照 / Async lighting
async-lighting:
enabled: true
# 光照线程池大小 / Lighting thread pool size
thread-pool-size: 2
# 批量处理阈值 / Batch threshold
batch-threshold: 16
# 光照传播队列 / Propagation queue
propagation-queue:
# 分层队列(Starlight核心算法)/ Layered queue (Starlight core)
# 说明:16层队列,按光照等级0-15分层处理
# Description: 16-layer queue, processes by light level 0-15
use-layered-queue: true
# 最大传播距离 / Max propagation distance
max-propagation-distance: 15
# 天空光缓存 / Skylight cache
skylight-cache:
enabled: true
# 缓存有效期(毫秒)/ Cache duration (milliseconds)
cache-duration-ms: 100
# 高级优化 / Advanced optimizations
advanced:
# 启用去重 / Enable deduplication
# 说明:防止同一位置重复排队
# Description: Prevent same position from queuing multiple times
enable-deduplication: true
# 动态批量大小调整 / Dynamic batch adjustment
# 说明:根据TPS自动调整批量大小
# Description: Auto-adjust batch size based on TPS
dynamic-batch-adjustment: true
# 输出高级统计 / Log advanced stats
log-advanced-stats: false
# ==========================================
# 性能监控 / Performance Monitoring
# ==========================================
performance:
# 调试日志 / Debug logging
# 警告:会刷屏 / Warning: Console spam!
debug-logging: false
# 性能指标收集 / Metrics collection
# 说明:显示异步任务执行时间和队列大小
# Description: Show async task execution times and queue sizes
enable-metrics: true
#
# 提示 / Tip: 更多线程≠更好性能!从推荐值开始调整。
# More threads ≠ better performance! Start with recommended values.Q: 插件无法加载?
检查启动参数是否包含 -Dleavesclip.enable.mixin=true
Q: MSPT没有明显改善?
- 确认实体数量 > 50(少于50不会启用并行优化)
- 逐步开启异步AI优化(从村民开始)
- 使用Spark查看详细性能
Q: 如何验证优化效果?
使用 Spark 性能分析工具:
/spark profiler start --timeout 5m
# 等待5分钟
/spark profiler stop
观察MSPT变化和CompletableFuture占比
Q: 插件兼容性?
✅ 与大部分插件兼容 📧 遇到冲突请提交Issue
Q: 推荐的开启顺序?
建议逐步开启,观察效果:
- 先开启
entity-tick-parallel(并行实体Tick) - 再开启
villager-optimization(村民优化) - 最后开启
universal-ai-optimization(通用优化)
每次开启后运行一段时间,确认无问题再开启下一个。
# 克隆项目
git clone https://github.com/virgil698/Aki-Async.git
cd Aki-Async
# 构建
./gradlew clean build
# 产物位于
build/libs/Aki-Async-2.0.0-SNAPSHOT.jar本项目采用 GPL-3.0 License 开源协议
这是完全免费的社区版本:
- ✅ 完全免费使用
- ✅ 允许商业用途
- ✅ 源代码开放
- ✅ 24个优化模块完整功能
- ✅ 65种生物全覆盖
- ✅ 长期维护更新
根据GPL-3.0协议:
- ✅ 可自由使用、修改、分发
- ✅ 可用于商业服务器
⚠️ 修改后的版本必须同样开源(GPL-3.0)⚠️ 必须保留原作者版权声明
本项目参考了以下优秀开源项目:
| 项目 | 贡献 |
|---|---|
| Starlight / ScalableLux | 光照传播算法 |
| Lithium | 性能优化思路 |
| ServerCore | 热点优化方案 |
| FerriteCore | 内存优化策略 |
| Async | 异步化边界设计 |
| Leaves | Mixin支持 |
- 本插件通过Mixin修改服务端核心代码,请先在测试服务器验证
- 不保证与所有插件100%兼容
- 如遇问题请提交 Issue
💬 Issues: GitHub Issues
📧 Email: virgil698@sky233.top
💬 Discord: xiaokong23357(virgil698)
Edition: Community(社区版) | Version: 2.0.0 | License: GPL-3.0 | Author: Virgil
如果觉得有用,请给个 ⭐ Star 支持开发!
Made with ❤️ for Minecraft Server Optimization