COWMODSКаталог модов

Redstonecompiler

JIT-compiles redstone circuits to bytecode for faster large machines.

Автор: aaa67951525обновлён 9 июн. 2026 г.
Оптимизация

Описание

image

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

MetricVanillaRedstoneCompilerImprovement
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)

MetricVanillaRedstoneCompilerImprovement
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)

MetricVanillaRedstoneCompilerImprovement
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)

MetricVanillaRedstoneCompilerImprovement
Single update~12ms~0.12ms~100x
Server TPS impactSevere (~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 TypeRecommended?Expected Gain
Single redstone lineNoNone
Repeater chains✅ Strongly~28x
Adders / ALUs✅ Strongly40~60x
Large combinational logic✅ Highly60~100x
Dynamic sequential circuits❌ N/ANone

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:

  1. Enable toggle — one-click disable to revert to vanilla behavior
  2. Detection range — chunk radius centered on player (1~32), default 8
  3. Compilation mode — Aggressive (all) / Normal (medium) / Passive (small only), balance performance vs overhead
  4. Max circuits per tick — rate-limit to prevent stutter during bulk compilation
  5. Debug mode — verbose logging for troubleshooting
  6. Log compiled circuits — track every compilation
  7. 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).

Последние версии

Все версии →
alpha

Redstonecompiler 0.2.0-alpha

0.2.0-alpha
9 июн. 2026 г.124Minecraft: 1.20.1fabric, quilt
Скачать
Что нового
### Critical Bug Fixes (3) **Bug 1 — Output power discarded** `CircuitManager.applyOutput()` called `updateNeighborsAlways()` without actually setting the redstone signal strength. The `power` value computed by the compiled circuit was silently dropped. > Fix: replaced with `world.setBlockState(pos, state.with(POWER, clamped), 2)` — actually writes the signal value. **Bug 2 — Input captured stale value** `RedstoneWireMixin` injected at HEAD and called `ci.cancel()`, but `state.get(POWER)` returned the pre-update value. Vanilla's recalculation never had a chance to run. > Fix: added `@Invoker("getReceivedRedstonePower")` to directly call the vanilla private method for the correct input signal strength. **Bug 3 — Self-triggered infinite loop** `applyOutput` → `setBlockState` → triggered `neighborUpdate` → Mixin intercepted again → called `onInputChanged`…infinite recursion. > Fix: added `ThreadLocal<Boolean> APPLYING_OUTPUTS` re-entrancy guard, checked in all 3 Mixins (RedstoneWireMixin, BlockChangeMixin). ### Mixin Strategy Optimization - **Before**: intercepted ALL circuit wire `neighborUpdate` calls, cancelled everything → signals couldn't propagate correctly - **After**: only intercepts **INPUT nodes** (wires receiving external signals); non-input nodes pass through to vanilla logic normally ### Other Improvements - `executedThisTick` deduplication: same circuit won't execute twice in the same tick - `BlockChangeMixin`: added `isApplyingOutputs()` guard to prevent self-invalidation during output application
alpha

Redstonecompiler 0.1.0-alpha

0.1.0-alpha
9 июн. 2026 г.27Minecraft: 1.20.1fabric, quilt
Скачать
Что нового
## Core Features **Circuit Detection** ✅ — CircuitDetector scans redstone wires/repeaters/comparators connectivity graph, identifies closed circuits **Bytecode Compilation** ✅ — BytecodeGenerator uses ASM to dynamically generate Java class, compiles circuit logic into native bytecode **Circuit Management** ✅ — CircuitManager manages compiled circuit lifecycle, replaces vanilla redstone update calls **Mixin Injection** ✅ — 3 Mixins intercept vanilla redstone update entry points (RedstoneWireMixin, WorldMixin, BlockChangeMixin) **Input Response** ✅ — On redstone signal change triggers onInputChanged, calls compiled circuit to recalculate output ## Supported Redstone Components **Redstone Wire** ✅ **Repeater** ✅ **Comparator** _— COMPARE mode_ ✅ **Comparator** _— SUBTRACT mode_ ✅ **NOT expression** ✅ **GreaterThan expression** ✅ **Subtract clamp [0,15]** ✅ ## Configuration System 7 config options: enable toggle, detection range (chunk radius), compilation mode (aggressive/normal/passive), max circuits per tick, debug mode, log compiled circuits, skip redstone wire Cloth Config GUI (optional dependency, won't crash without it) Mod Menu integration, config button entry i18n support: zh_cn.json + en_us.json, auto-switches following game language Code Quality Dependency tiers: depends (required) / recommends (recommended) / suggests (suggested) strictly separated ASM not JiJ-bundled: provided by Fabric Loader at runtime, avoids classloader conflict Client entrypoint: RedstoneCompilerClient ensures Mod Menu correctly identifies it as "Mod" not "Library" Global error guard: main onInitialize() try-catch prevents silent crash hiding WeakHashMap cleanup cap: MAX_WORLD_ENTRIES=100 prevents memory leak Not Yet Implemented Dynamic circuit recompilation (auto-invalidate and recompile on circuit structure change) Full server-side testing Circuit visualization debug overlay Full modeling of pistons/observers and other non-signal components