TrackFastRack
一个轻量级的独立 Forge 1.20.1 模组,通过为发布的 Create 模组应用轨道网络泛洪填充优化,修复了 Create 铁路代码中的一个性能热点——无需使用 Fork 版的 Create。
问题所在
每当放置或破坏轨道时,Create 的 TrackGraph#findDisconnectedGraphs 方法会对整个铁路网络运行连通分量的泛洪填充算法。在已发布的 Create 版本(≤ 6.0.8)中,BFS 前沿队列使用的是 ArrayList,而通过 ArrayList#remove(0) 从头部弹出元素会在每次弹出时移动整个底层数组——这使得泛洪填充的时间复杂度变为 O(n²)。
在一个大型铁路网络(约 8 万个节点)上,单次轨道修改可能会遍历数十亿个元素,导致在建造或重新规划长距离列车线路时出现明显的卡顿和延迟峰值。
修复方案
本模组注入单个 Mixin,将前沿队列替换为 ArrayDeque(poll() 操作的时间复杂度为 O(1)),并将 stream().findFirst() 替换为普通的迭代器,从而将泛洪填充的时间复杂度降低至 O(n)。此更改忠实移植自 Create fork 的提交 272e97604(“优化列车网络热点路径”)。
验证是否生效
在游戏启动时,模组会记录日志 TrackGraph flood-fill self-test OK,证明优化后的方法在运行时正确绑定并执行。
TrackFastRack
A tiny standalone Forge 1.20.1 mod that fixes a performance hot-spot in Create's railway code by applying
the track-network flood-fill optimisation to the published Create mod — no forked Create needed.
The problem
Whenever a track is placed or broken, Create's TrackGraph#findDisconnectedGraphs runs a connected-component
flood fill over the entire rail network. In released Create (≤ 6.0.8) the BFS frontier is an ArrayList, and
popping from the head via ArrayList#remove(0) shifts the whole backing array on every pop — making the flood
fill O(n²).
On a large rail network (~80k nodes), a single track modification can walk billions of elements, causing
noticeable stutter and lag spikes while building or rerouting long train lines.
The fix
This mod injects a single Mixin that replaces the frontier with an ArrayDeque (poll() is O(1)) and swaps
stream().findFirst() for a plain iterator, turning the flood fill into O(n). The change is a faithful port
of Create fork commit 272e97604 ("Optimise train network hot paths").
Verify it's working
On game start the mod logs TrackGraph flood-fill self-test OK, proving the optimised method bound correctly at
runtime.
评论 0
登录后参与评分
还没有评论,来抢沙发吧