Commit feefde8
committed
Halve peak grid storage: f32 for elevation heights + water blend
Two full-world grids were stored as `Vec<Vec<f64>>`, doubling their
resident size for no precision gain:
1. `ElevationData::heights` (computed by the elevation pipeline, used by
`Ground::level` → `get_ground_level` on every block-placement hot
path). Values are rounded to integer Minecraft Ys at final placement,
so the full 15-digit f64 precision was wasted storage.
2. `LandCoverData::water_blend_grid` (Gaussian-blurred water mask used
by `ground.water_blend`). Values are bounded to `[0, 1]` and only
ever compared against a 0.5 threshold in the renderer — f32's ~7
decimal digits are overkill.
Both grids can hit 10+ million cells on a city-sized bbox, so dropping
each from 8 to 4 bytes/cell saves ~92 MB combined on a Munich-sized
area.
Postprocess, rotation, and Gaussian blur stay in f64 internally — the
downcast to f32 happens once at storage assignment
(`ElevationData` construction + `Ground::set_elevation_data` +
`compute_water_blend_smooth` output). Read sites in `Ground` widen back
to f64 for bilinear interpolation so rounding behaviour matches the
previous implementation bit-for-bit on integer-valued elevations.
Local measurement on CI bbox `48.125768,11.552296,48.148565,11.593838`
with `--terrain` (integer seconds, 5 runs):
main baseline: ~24 s
post-fix: ~20-21 s (−3-4 s)
Most of the speed gain comes from reduced memory bandwidth on the
`Ground::level` hot path — the elevation grid now fits tighter in L2/L3
cache during the per-block lookup loop. Peak memory saving lands
wherever in the pipeline the grids are resident (mainly during element
processing + ground generation + save), independent of the gen-time
win.
Tests (65/65), clippy `-D warnings`, fmt clean.1 parent 8009695 commit feefde8
3 files changed
Lines changed: 56 additions & 16 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | | - | |
23 | | - | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
24 | 30 | | |
25 | 31 | | |
26 | 32 | | |
| |||
223 | 229 | | |
224 | 230 | | |
225 | 231 | | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
226 | 241 | | |
227 | | - | |
| 242 | + | |
228 | 243 | | |
229 | 244 | | |
230 | 245 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
175 | 175 | | |
176 | 176 | | |
177 | 177 | | |
178 | | - | |
179 | | - | |
180 | | - | |
181 | | - | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
182 | 185 | | |
183 | 186 | | |
184 | 187 | | |
| |||
297 | 300 | | |
298 | 301 | | |
299 | 302 | | |
300 | | - | |
301 | | - | |
302 | | - | |
303 | | - | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
304 | 312 | | |
305 | 313 | | |
306 | 314 | | |
| |||
318 | 326 | | |
319 | 327 | | |
320 | 328 | | |
321 | | - | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
322 | 335 | | |
323 | 336 | | |
324 | 337 | | |
| |||
389 | 402 | | |
390 | 403 | | |
391 | 404 | | |
392 | | - | |
393 | | - | |
| 405 | + | |
| 406 | + | |
394 | 407 | | |
395 | 408 | | |
396 | 409 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
71 | | - | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
72 | 78 | | |
73 | 79 | | |
74 | 80 | | |
| |||
94 | 100 | | |
95 | 101 | | |
96 | 102 | | |
97 | | - | |
| 103 | + | |
98 | 104 | | |
99 | 105 | | |
100 | 106 | | |
| |||
110 | 116 | | |
111 | 117 | | |
112 | 118 | | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
113 | 122 | | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
114 | 126 | | |
115 | 127 | | |
116 | 128 | | |
| |||
0 commit comments