| |
๐ Pair with WorldFlow to generate new terrain faster across all CPU cores and stop worldgen freezes! |
ChunkFlow
Next-Generation Chunk Loading, Lock-Free Region I/O & Directional Chunk Streaming for Minecraft 1.12.2
๐ What is ChunkFlow?
ChunkFlow is a modern, high-performance optimization mod for Minecraft 1.12.2 (running on Cleanroom or Minecraft Forge) that revolutionizes how the game reads, decompresses, and streams existing chunks from disk.
Ever flown an Elytra or ridden a high-speed mount only to slam into unrendered, invisible chunk borders? Ever noticed your server freezing with massive tick lag spikes whenever players explore existing terrain?
That happens because Minecraft 1.12.2 still relies on single-threaded I/O architectures and synchronized disk locks designed over a decade ago. ChunkFlow completely overhauls this pipeline, delivering up to 2.9x – 5.9x faster chunk loading throughput while ensuring 100% data integrity and stability.
โก The Problems ChunkFlow Solves
- The 1-Thread Async Bottleneck: Forge provides an asynchronous chunk loader (
ChunkIOExecutor), but hardcodes its core pool size to 1 thread with an unbounded queue. This means whether your server has 4 cores or 64 cores, every chunk read from disk is bottlenecked behind a single worker thread! - Region File Serialization: Vanilla uses a shared file cursor on region (
.mca) files and locks the entire file withsynchronized(this). When multiple players or workers need chunks from the same region, their reads are forced into a single-file line. - Catastrophic Cache Wipes: When vanilla's region file cache reaches 256 open files, it doesn't evict the oldest file it purges and closes all 256 files at once, causing brutal disk spikes and server lag.
- The Elytra "Void Flight" Syndrome: The vanilla server calculates chunk send priority using radial circles around player coordinates. When flying fast, the server wastes time and bandwidth sending chunks behind you rather than the ones directly ahead of you.
- Garbage Churn: Vanilla allocates a new
java.util.zip.Inflaterdecompressor for every chunk read from disk, creating memory pressure and GC micro-stutters.
๐ Key Features
- ๐ Lock-Free Positional Region I/O: Replaces vanilla's synchronized file cursor with non-blocking positional
FileChannel.read(pread64on Linux, overlapped I/O on Windows). Multiple CPU threads can now read different chunks from the exact same.mcafile simultaneously! - ๐งต Multi-Core Asynchronous Loading: Automatically expands Forge's
ChunkIOExecutoracross your available CPU cores (cores - 1, auto-default capped at 4 for spindle drives, or manually configured up to 64). - ๐ฏ Velocity-Projected Directional Chunk Sending: Calculates player heading and speed (walking, riding, Elytra flying, or modded jetpacks) and prioritizes chunk network sending in a forward cone. No more flying into the void!
- ๐ Pooled Thread-Local Zlib Decompression: Reuses thread-local
Inflaterinstances with exact buffer allocation, eliminating decompressor allocation garbage and GC stalls. - ๐ก๏ธ Atomic Reader Leases & Self-Healing Reads: Atomic CAS reader leases (
RegionFileLease) prevent the cache trimmer from evicting a file mid-read. If an eviction race ever occurs, ChunkFlow transparently re-opens the live file guaranteeing zero false nulls and zero lost chunks. - ๐งน Intelligent Cache Trimming: Expands the region file cache to 512 (configurable up to 4,096) and performs clean, idle-only LRU trimming instead of vanilla's devastating full-cache wipes.
- ๐ StampedLock Concurrency: Non-blocking optimistic offset table reads. Writers hold exclusive write stamps during sector reallocation, verified with 0 torn reads under extreme torture testing.
๐ Performance & Benchmarks
Measured using the ChunkFlow multi-threaded stress harness (RegionTorture):
| Benchmark Metric | Vanilla / Standard Forge | ChunkFlow 1.0.1 | Improvement |
|---|---|---|---|
| Region Read Throughput | ~91,650 reads/sec | ~268,784 reads/sec | +193% (2.93x faster) |
| High-Concurrency Reads | Serialized behind RAF lock | Fully parallel (pread64) |
Up to 5.9x faster |
| Concurrent Writer Integrity | Subject to race conditions | StampedLock / Zero torn reads | 100% Data Integrity |
| Zlib Inflater Allocations | 1 per chunk read | Pooled / Reused | ~100% Allocation Reduction |
| Region Cache Eviction | Destructive full purge (256) | Clean idle-only LRU trim | Zero Cache Thrashing |
| Elytra Chunk Streaming | Radial Euclidean (stalls ahead) | Velocity-projected cone | Eliminates Void Holes |
๐ฆ Requirements & Installation
Requirements:
- Minecraft:
1.12.2 - Mod Loader: Cleanroom
0.6.x+(recommended) or Minecraft Forge14.23.5.2847+ - Required Dependency: MixinBooter
10.2or newer - Java: Java 8 through modern Java 21+ runtimes supported.
Installation:
- Make sure MixinBooter (version 10.2 or higher) is installed in your
.minecraft/modsfolder. - Download
chunkflow-1.0.1.jarand place it in yourmodsfolder. - Launch the game!
Client vs Server: ChunkFlow is 100% server-side compatible! Clients do not need ChunkFlow installed to join a server running it. However, installing ChunkFlow on your client is highly recommended for singleplayer worlds and LAN games.
๐ ๏ธ In-Game Commands
Requires OP / Permission Level 2:
/chunkflow statsLive report of worker threads, pool capacity, off-thread chunks loaded, cached regions, and zlib reuse counters./chunkflow threads <0|n>Dynamically change the worker thread count at runtime (0= automaticcores - 1)./chunkflow toggleToggles async chunk I/O parallelism on or off without restarting./chunkflow region statsDisplays region read throughput, decompressed chunk counters, and zlib cache metrics./chunkflow region toggleToggles the fast lock-free region I/O path./chunkflow region clearResets cumulative region read statistics./chunkflow directional statsShows directional chunk sending metrics, biased calls, and boosted chunk counts./chunkflow directional toggleToggles velocity-projected directional chunk ordering./chunkflow directional clearResets directional metrics./chunkflow reloadHot-reloads settings fromconfig/chunkflow.cfg.
(Aliases: /chunkpipe, /cpipeline)
โ๏ธ Configuration
Config file: config/chunkflow.cfg
I/O Threads(Default:0): Number of chunk I/O worker threads.0selectscores - 1(capped at 4 for spindle disk safety). Can be raised up to64for high-end dedicated servers.Max Threads(Default:8): Upper bound for automatic thread allocation.Scale With Players(Default:false): Dynamically scales worker threads between min and max threads based on online player count.Max Cache Size(Default:512): Maximum number of region files kept in memory before idle eviction (Vanilla is 256). Range:64to4096.Velocity Bias Weight(Default:0.6): How aggressively forward chunks are prioritized when moving quickly (0.1 to 0.9).Min Velocity Threshold Sq(Default:0.04): Minimum player speed required to activate directional chunk sending.
โ Frequently Asked Questions (FAQ)
Q: Can ChunkFlow corrupt my world saves?
A: No. ChunkFlow only alters how existing chunks are read from disk and prioritized for network sending. World saving continues through standard write channels, guarded by StampedLock write stamps that prevent any concurrent reader conflict. Every build is verified against our comprehensive RegionTorture test suite with 0 torn reads.
Q: Does ChunkFlow generate new chunks?
A: No. ChunkFlow optimizes reading and streaming chunks that already exist on disk. If you are looking for parallel multi-threaded world generation for new chunks, pair ChunkFlow with its companion mod WorldFlow.
Q: Is ChunkFlow compatible with Chunk-Pregenerator?
A: Yes! ChunkFlow includes built-in detection for Chunk-Pregenerator and enables safe concurrent region file interop automatically.
Q: Can I use ChunkFlow in my modpack?
A: Absolutely! ChunkFlow is licensed under the open-source GPL-3.0 license. You are free to include it in any public or private modpack on CurseForge, Modrinth, FTB, or custom launchers.

