
RedstoneCompiler
将红石电路即时编译(JIT)为字节码。对于大型红石机械,速度提升 15~100 倍。
问题所在
如果你曾在 Minecraft 中建造过红石计算机、大型自动分类器或多位算术逻辑单元(ALU),你可能遇到过以下瓶颈:
- TPS 暴跌 —— 原版会单独扫描每一根红石线。大型电路每刻都会消耗数毫秒。
- 服务器卡顿 —— 单个玩家的红石巨型建筑会导致整个服务器性能下降。
RedstoneCompiler 解决了这个问题。
工作原理
传统的红石更新流程如下:
信号变化 → 遍历所有连接的红石线 → 逐线重新计算电力 → 输出结果
RedstoneCompiler 将其替换为:
信号变化 → 调用预编译的字节码 → 单次方法调用,完成所有逻辑计算 → 输出结果
关键技术:ASM 在运行时动态生成一个 Java 类,将整个电路的逻辑编译为原生 JVM 字节码。随后,JVM 的 JIT 编译器进一步优化这些代码为原生机器码,从而提供接近手写代码级别的性能。
性能表现(理论估算)
基于对 JVM 字节码执行与原版的红石更新的理论分析,以下是典型场景下的预期表现:
场景 1:单条红石线(15 个红石粉)
规模:15 个红石粉
结果:无明显差异。 小型电路在原版的处理速度已经足够快;编译开销大致抵消了任何潜在的性能增益。
场景 2:中继器信号链(64 个中继器)
规模:64 个串联的中继器
| 指标 |
原版 |
RedstoneCompiler |
提升幅度 |
| 每次更新时间 |
~4.2ms |
~0.15ms |
约 28 倍 |
原因:原版会在每次更新时单独扫描所有 64 个中继器以重新计算信号强度。编译后的版本通过单次方法调用完成此操作。注意:中继器的延迟(每级 1 刻)是原版设计的有意为之——该模组完全保留了这一机制,不会改变传播时序。
场景 3:8 位加法器
规模:约 200 个红石组件(含红石线、中继器和比较器)
| 指标 |
原版 |
RedstoneCompiler |
提升幅度 |
| 每次运算耗时 |
~0.8ms |
~0.02ms |
约 40 倍 |
| 连续 1000 次运算 |
~800ms |
~20ms |
约 40 倍 |
原因:原版在进行每次加法时会触发大规模的红石线扫描。编译后:所有逻辑包含在一个方法中。
场景 4:完整 ALU(4 位,8 种运算)
规模:约 800 个组件,8 种运算(ADD/SUB/AND/OR/XOR/NOT/SHL/SHR)
| 指标 |
原版 |
RedstoneCompiler |
提升幅度 |
| 单次 ALU 运算 |
~3.5ms |
~0.06ms |
约 58 倍 |
| 最大模拟时钟频率 |
~5Hz |
~300Hz |
约 60 倍 |
场景 5:大型静态逻辑机器(2000+ 组件)
规模:大规模组合逻辑(例如红石绘图仪、门阵列)
| 指标 |
原版 |
RedstoneCompiler |
提升幅度 |
| 单次更新 |
~12ms |
~0.12ms |
约 100 倍 |
| 服务器 TPS 影响 |
严重(约 8 TPS) |
可忽略不计(约 19.8 TPS) |
保持完整 TPS |
场景 6:动态时钟电路
规模:包含大量中继器锁存器、计时器、时序逻辑的电路
结果:无明显提升。 动态电路依赖于逐刻的状态转换,这更适合原版的处理方式。RedstoneCompiler 会自动跳过此类电路(可通过 skipRedstoneWire 配置)。
总结
| 电路类型 |
推荐? |
预期增益 |
| 单条红石线 |
否 |
无 |
| 中继器链 |
✅ 强烈建议 |
约 28 倍 |
| 加法器 / ALU |
✅ 强烈建议 |
40~60 倍 |
| 大型组合逻辑 |
✅ 高度推荐 |
60~100 倍 |
| 动态时序电路 |
❌ 不适用 |
无 |
结论:你的电路越大、越偏向组合逻辑,RedstoneCompiler 的帮助就越大。
支持的红石组件
- 红石线 ✅
- 中继器 ✅
- 比较器 — 比较模式(COMPARE)✅
- 比较器 — 减法模式(SUBTRACT)✅
- 非逻辑(取反)✅
- 大于逻辑 ✅
配置
7 个可调参数,可通过 Mod Menu + Cloth Config GUI 进行调整:
- 启用开关 —— 一键禁用以恢复原版行为
- 检测范围 —— 以玩家为中心的区块半径(1~32),默认值为 8
- 编译模式 —— 激进(全部)/ 正常(中等)/ 被动(仅小型),平衡性能与开销
- 每刻最大电路数 —— 限制速率以防止批量编译期间的卡顿
- 调试模式 —— 详细日志记录以便故障排除
- 记录已编译电路 —— 跟踪每次编译操作
- 跳过红石线 —— 仅编译中继器/比较器用于测试
注意:Cloth Config API 为可选依赖。若无此 API,请手动编辑 config/redstonecompiler.json。
兼容性
要求
- Minecraft 1.20.1
- Fabric Loader ≥ 0.15.11
- Fabric API —— 必需
- Java 17+
推荐搭配
- Cloth Config API —— 图形化配置界面
- Mod Menu —— 游戏内模组列表中的配置访问入口
已知冲突
- 暂无已知冲突。该模组仅拦截红石更新调用,从不修改原版方块行为。
- 可与 Lithium、Alternate Current 及其他优化模组安全共存(编译发生在红石更新之前,无干扰)。

RedstoneCompiler
JIT-compiles redstone circuits to bytecode. 15~100x faster for large redstone machines.
The Problem
If you've ever built a redstone computer, a massive auto-sorter, or a multi-bit ALU in Minecraft, you've probably hit these walls:
- TPS plummets — vanilla scans every redstone wire individually. Large circuits eat milliseconds per tick.
- Server lag — one player's redstone mega-build drags down the entire server.
RedstoneCompiler fixes this.
How It Works
Traditional redstone update flow:
Signal change → Traverse all connected wires → Recalculate power per-wire → Output
RedstoneCompiler replaces it with:
Signal change → Call pre-compiled bytecode → One method call, all logic computed → Output
Key technique: ASM dynamically generates a Java class at runtime, compiling the entire circuit's logic into native JVM bytecode. The JVM's JIT compiler then further optimizes this into native machine code, delivering hand-written-code-level performance.
Performance (Theoretical Estimates)
Based on theoretical analysis of JVM bytecode execution vs vanilla redstone updates, here's what to expect across typical scenarios:
Scenario 1: Single Redstone Line (15 dust)
Scale: 15 redstone dust
Result: No significant difference. Small circuits are fast enough in vanilla; compilation overhead roughly cancels out any gain.
Scenario 2: Repeater Signal Chain (64 repeaters)
Scale: 64 repeaters in series
| Metric |
Vanilla |
RedstoneCompiler |
Improvement |
| Per-update time |
~4.2ms |
~0.15ms |
~28x |
Why: Vanilla scans all 64 repeaters individually to recalculate signal strength on each update. The compiled version does it in a single method call. Note: repeater delay (1 tick per stage) is intentional vanilla design — the mod fully preserves it and does not alter propagation timing.
Scenario 3: 8-bit Adder
Scale: ~200 redstone components (wires + repeaters + comparators)
| Metric |
Vanilla |
RedstoneCompiler |
Improvement |
| Per-operation |
~0.8ms |
~0.02ms |
~40x |
| 1000 consecutive ops |
~800ms |
~20ms |
~40x |
Why: Vanilla triggers massive wire scanning per addition. Compiled: all logic in one method.
Scenario 4: Full ALU (4-bit, 8 operations)
Scale: ~800 components, 8 operations (ADD/SUB/AND/OR/XOR/NOT/SHL/SHR)
| Metric |
Vanilla |
RedstoneCompiler |
Improvement |
| Single ALU operation |
~3.5ms |
~0.06ms |
~58x |
| Max simulated clock rate |
~5Hz |
~300Hz |
~60x |
Scenario 5: Large Static Logic Machine (2000+ components)
Scale: Massive combinational logic (e.g. redstone plotter, gate arrays)
| Metric |
Vanilla |
RedstoneCompiler |
Improvement |
| Single update |
~12ms |
~0.12ms |
~100x |
| Server TPS impact |
Severe (~8 TPS) |
Negligible (~19.8 TPS) |
Full TPS maintained |
Scenario 6: Dynamic Clocked Circuits
Scale: Circuits with many repeater latches, timers, sequential logic
Result: No significant improvement. Dynamic circuits rely on tick-by-tick state transitions, which suit vanilla processing. RedstoneCompiler automatically skips these (configurable via skipRedstoneWire).
Summary
| Circuit Type |
Recommended? |
Expected Gain |
| Single redstone line |
No |
None |
| Repeater chains |
✅ Strongly |
~28x |
| Adders / ALUs |
✅ Strongly |
40~60x |
| Large combinational logic |
✅ Highly |
60~100x |
| Dynamic sequential circuits |
❌ N/A |
None |
Bottom line: the bigger and more combinational your circuit, the more RedstoneCompiler helps.
Supported Redstone Components
- Redstone Wire ✅
- Repeater ✅
- Comparator — COMPARE mode ✅
- Comparator — SUBTRACT mode ✅
- NOT logic (inversion) ✅
- GreaterThan logic ✅
Configuration
7 tunable parameters, adjustable via Mod Menu + Cloth Config GUI:
- Enable toggle — one-click disable to revert to vanilla behavior
- Detection range — chunk radius centered on player (1~32), default 8
- Compilation mode — Aggressive (all) / Normal (medium) / Passive (small only), balance performance vs overhead
- Max circuits per tick — rate-limit to prevent stutter during bulk compilation
- Debug mode — verbose logging for troubleshooting
- Log compiled circuits — track every compilation
- Skip redstone wire — compile only repeaters/comparators for testing
Note: Cloth Config API is optional. Without it, edit config/redstonecompiler.json manually.
Compatibility
Requirements
- Minecraft 1.20.1
- Fabric Loader ≥ 0.15.11
- Fabric API — required
- Java 17+
Recommended Companions
- Cloth Config API — graphical configuration UI
- Mod Menu — in-mod-list config access
Known Conflicts
- None known. The mod only intercepts redstone update calls, never modifies vanilla block behavior.
- Safe to use with Lithium, Alternate Current, and other optimization mods (compilation happens before redstone updates, no interference).
评论 0
登录后参与评分
还没有评论,来抢沙发吧