Initial commit: Terrafier v0.1.0

- Core world model (World, Dimension, Tile, Terrain, Platform)
- NBT reader/writer with full tag support
- Anvil region (.mca) format reader with chunk parsing
- Block palette compression and export
- Biome database with Minecraft 1.21 biomes
- CLI commands: new, import, export, info, render
- GUI application with egui (viewport, tools, undo/redo)
- Noise-based heightmap generation and editing operations

License: GPL-3.0-or-later
This commit is contained in:
loki5512344 2026-06-15 19:14:11 +02:00
commit 91835402b3
94 changed files with 12372 additions and 0 deletions

42
docs/benchmarks/baseline.md Executable file
View file

@ -0,0 +1,42 @@
# Baseline Benchmarks
> Generated: 2026-05-27
> Hardware: Intel/AMD, Windows
> Rust: release profile (opt-level=3, LTO, codegen-units=1)
## NBT
| Benchmark | Time (µs) | Notes |
|-----------|-----------|-------|
| parse_small_compound | 3.99 µs | 10-field Compound |
| parse_large_longarray_4096 | 52.2 µs | LongArray[4096] |
| serialize_compound | 2.39 µs | 10-field Compound |
| serialize_large_longarray | 12.4 µs | LongArray[4096] |
| gzip_roundtrip | 59.5 µs | compress + decompress |
| roundtrip_small | 6.77 µs | serialize + parse |
## Render
| Benchmark | Time (ms) | Notes |
|-----------|-----------|-------|
| one_tile_scale1 | 0.67 ms | 128×128 full-res |
| one_tile_scale2 | 0.60 ms | 64×64 |
| one_tile_scale4 | 0.61 ms | 32×32 |
| 3x3_tiles_scale1 | 3.08 ms | 384×384 full-res |
| 3x3_tiles_scale2 | 2.70 ms | 192×192 |
| 3x3_tiles_scale4 | 2.60 ms | 96×96 |
## World
| Benchmark | Time | Notes |
|-----------|------|-------|
| new_default | **1.53 ms** | 3×3 tiles with noise (optimized with rayon: was 10.2ms) |
| height_operation | 11.4 µs | radius=10, delta=5 |
| paint_operation | 4.18 µs | radius=10 |
| serialize_json | 5.25 ms | 3×3 tiles |
| deserialize_json | 6.37 ms | 3×3 tiles |
| render_image_scale4 | 1.98 ms | via render_to_image |
## Hot-path Summary
All benchmarks are **below 10ms**. The only candidate (World::new at 10.2ms) was optimized with parallel tile generation via `rayon` — now **1.5ms (85% faster)**.

45
docs/benchmarks/profile.md Executable file
View file

@ -0,0 +1,45 @@
# Hot-spot Analysis
> Updated: 2026-05-27
## Results
After baseline measurement, **only 1 benchmark exceeded 10ms**:
| Benchmark | Baseline | Optimized | Improvement |
|-----------|----------|-----------|-------------|
| `world/new_default` | **10.2 ms** | **1.53 ms** | **85%** |
All other benchmarks are well within the threshold (<7ms).
## Optimisation Applied
### `World::new()` — parallel tile generation
**Problem**: `World::new()` generated 9 noise heightmaps sequentially in nested `for` loops
(`-1..=1 × -1..=1`). Each tile calls `NoiseHeightMap::generate()` which does 16384 noise
samples × noise function calls. Total: 9 × 16384 = 147,456 noise evaluations.
**Fix**: Replaced sequential loop with `rayon::par_iter()` over the tile coordinates.
Noise heightmap generation per tile is embarrassingly parallel — tiles are fully independent.
**Result**: 10.2ms → 1.53ms (6.7x speedup on 8-core machine).
## Other Candidates (no action needed)
### NBT parsing (max 52 µs)
No action needed — already below 100µs. Zero-copy optimisations would add complexity
with negligible benefit.
### Render (max 3.1 ms)
No action needed — pixel-by-pixel rendering at 3ms for 384×384 is acceptable for a
preview renderer. If tile count grows to 100+, chunk-level parallelism via rayon
would help. Not needed now.
### JSON serialization (max 5.3 ms / 6.4 ms)
Bottleneck is serde serializing 9 tiles × 16384-element arrays. Potential future optimisations:
- Streaming serialization with `serde_json::to_writer`
- Custom serializer using binary formats
- Compressed tile data representation
Not needed now — user-facing operations (`new`, `paint`, `height` edits) are sub-millisecond.