Skip to content

perf: accelerate verified voxel building image processing - #303

Open
mkrieger95 wants to merge 2 commits into
ZallaxDev:integrationfrom
mkrieger95:investigate/pillow-bulk-pixel-processing
Open

mkrieger95 wants to merge 2 commits into
ZallaxDev:integrationfrom
mkrieger95:investigate/pillow-bulk-pixel-processing

Conversation

@mkrieger95

@mkrieger95 mkrieger95 commented Nov 21, 2026 •

Copy link
Copy Markdown

Summary

Speed up voxel building generation and its image-verification proofs using output-preserving Pillow/image-processing changes. This follows #296 and retains its parallel interior preparation and flat-floor proof rendering. No asset, rendering, geometry, Python support, dependency or ROM-format change is intended.

  • Compose each 16×16 metatile with one Pillow putdata, retaining the existing cache key and defensive copy semantics.
  • Preindex background colours for building_art rather than rescanning every ground tile at each covered pixel.
  • Avoid unnecessary barycentric calculations and cache row offsets/framebuffers in Raster.draw; retain triangle acceptance threshold, depth, texture sampling and shading.
  • Avoid unnecessary reads in orthographic image comparisons; preserve exact wrong/missing/extra counters and proof diagnostic colours.
  • Cache linear-time nearest-visible-neighbour row lookups for interior floor marks, preserving the original two-sided colour checks.
  • Use native alpha bounding boxes/bulk pixel extraction in small Pillow hot paths.
  • Keep permanent randomized production-function equivalence tests for the Pillow helpers, metatile and building art, triangle colour/depth/ownership, orthographic diagnostic pixels, and interior floor marks.

Verified results against latest merged #296

CI #913: all jobs passed. On identical prepared sources using Python 3.15.2, Pillow 13.0.0, pinned integration baseline 6de1c53, PYTHONHASHSEED=0, and five alternating A/B pairs per configuration:

Generator Workers Baseline median Optimized median Savings
Buildings, with image proof verification 1 242.503 s 226.219 s 16.285 s (6.72%)
Buildings, with image proof verification 4 233.437 s 216.244 s 17.193 s (7.37%)
Relief export 1-building-worker run 181.302 s 181.592 s -0.291 s (-0.16%)
Relief export 4-building-worker run 189.477 s 186.070 s +3.407 s (+1.80%)

The building improvement was consistent in all five measurements for both worker configurations. Relief results are mixed; no robust relief speedup is claimed.

All generated primary buildings and relief files and the windowlights sidecar had identical SHA-256 hashes across baseline/candidate and every repeat. The 3DS build, permanent image semantics/host tests and both Python audits also passed.

1-worker benchmark artifact · 4-worker benchmark artifact.

Earlier CI #899 likewise measured a 7.15% verified-building speedup against the older pre-#296 baseline. The initial microbench-only changes had no measurable whole-generator benefit in CI #891; the substantive image/raster pass accounts for the measurable combined speedup. We have not independently attributed the saving to each individual change.

Review / verification checklist

  • Rebase and reconcile against merged Speed up 3DS development builds and voxel checks #296 on integration.
  • Confirm meaningful repeated 1-worker and production-like 4-worker verified building gains against the latest baseline.
  • Compare generated binary SHA-256 outputs and windowlights sidecars across 20 combined measured generator passes (10 baseline/candidate runs in each worker matrix).
  • Preserve legacy algorithm behaviour in permanent randomized pixel, depth, owner, proof-counter and diagnostic-pixel regression tests.
  • Pass ordinary build-3DS, host tests and Python audits on the benchmark branch (CI #913).
  • Remove temporary long benchmark/profiling jobs and one-off scripts; retain permanent equivalence tests (cleanup commit 5c5c433).
  • Confirm the post-cleanup CI run is green.
  • Final maintainer review; a hardware 3DS spot-check of representative building/room proof visuals is recommended before merge.

This remains draft until the final post-cleanup CI pass. Full generated asset hashes and host pixel equivalence tests are strong evidence against visual regressions, but they are not a substitute for actual 3DS hardware inspection. No broad build-wall-clock reduction is claimed from a generator-only benchmark.

Copy link
Copy Markdown
Author

Initial investigation is in place (commits 26d35c3, 95e03c3), kept draft intentionally.

Isolated synthetic microbenchmarks (local Pillow 12.3.0, not pinned Pillow 13.0.0; best of five repeats):

  • 64×64 card alpha-bottom scan using Pillow native threshold + bbox: 83.8× faster than scanning every pixel with getpixel.
  • 16×16 RGB palette collection using flattened pixels: 4.0× faster than 256 individual getpixel calls.
  • 16×16 stair-tile luminance sampling using one bulk pixel read: 5.8× faster than repeated per-channel getpixel calls.

I also tested Pillow getcolors() for 16×16 tiles: slower, so it is not used. The new regression fixture checks the production alpha helper, RGB palette helper and actual riser_mask against old algorithms across deterministic randomized inputs and edge conditions; it has passed the host-tests check on the initial commit. Full 3DS verification and full-generator before/after wall-clock and SHA-256 comparisons are not yet confirmed. No overall build-time speedup is claimed. Please keep this as an investigational draft until those gates are met. Note the potential overlap with #296's building-generator changes.

Copy link
Copy Markdown
Author

Pinned-environment update: The latest host CI run on Python 3.15.2 / Pillow 13.0.0 passed the actual production-function equivalence fixture, and all host/Python audits are green. The non-gating diagnostic benchmark in CI run 44914225373 reported:

Synthetic operation Old Candidate Ratio
64×64 alpha-bottom scan 0.1528 s 0.0014 s 111.42×
16×16 RGB palette 0.1071 s 0.0248 s 4.31×
16×16 stair luminance 0.1827 s 0.0278 s 6.57×

These measurements repeat each isolated operation many times; they are not full generator wall-clock savings. The full build-3ds job is still in progress, and byte-identical full-generator SHA-256 comparisons to the base are still part of the draft's remaining release gate.

Copy link
Copy Markdown
Author

Controlled A/B result: CI #891 completed successfully (run). Five alternating baseline/candidate runs in the same pinned Python 3.15.2 / Pillow 13.0.0 container, using identical prepared inputs and PYTHONHASHSEED=0:

Generator Baseline median Optimized median Median delta
Buildings 164.796 s 164.806 s 0.010 s slower (-0.01% gain)
Relief 141.312 s 142.148 s 0.836 s slower (-0.59% gain)

The sum of per-generator medians is 306.108 s baseline vs 306.954 s candidate (0.846 s slower; ~0.28%). All 20 generated main outputs had identical SHA-256 hashes across the two versions and all five iterations, and the windowlights sidecar hash also matched. The A/B benchmark and all ordinary CI jobs passed. Result: microbenchmarks do not translate into a demonstrated end-to-end generator improvement. Keep draft; avoid claiming a speedup from these changes. A second run (#892, with leaner input preparation) is in progress and may independently confirm the result.

Artifact containing results.json, summary.md and individual iteration logs: CI #891.

Copy link
Copy Markdown
Author

CI #893 failure triaged and patched in ce818cf. Only the new pillow-sampling-profile job failed; build-3ds, host tests, Python 3.11 and 3.15.2 audits all passed. The verified buildings generator completed (~212.7 s) and relief sampling completed, but tools/profile_voxel.py raised UnicodeDecodeError while reading the sampler's .pstats output via pstats.Stats. The fix uses Python 3.15's readable profiling.sampling --pstats stdout summary (--sort cumtime --limit 60) and writes the hotspot table directly; the existing binary pstats.Stats path remains for cProfile tracing only. This is profiling-report handling, not evidence of a change to generated assets. New CI triggered; leave the PR draft until the profiling job passes and its hotspots are reviewed.

Copy link
Copy Markdown
Author

CI #895 diagnostic and follow-up fix (latest commit fb77d32): The only failed check was pillow-sampling-profile; 3DS build, host checks and both Python audits passed. The Python 3.15 sampler did produce complete results for verified buildings (~269,119 samples). The helper erroneously searched for Profile Stats (Mode:; the real output begins Profile Stats: followed by the nsamples table. Changed parser to recognize real sample tables, added an exact-heading regression fixture in host CI (plus a follow-up fixture-newline correction), and left the PR in draft. CI #895, new verification #897.

We recovered usable profiling data from #895's uploaded artifact despite the failed reporter. Promising substantive hot spots in verified buildings include interior_specs._mark_under (~9.6s direct), Raster.draw (~8.9s + ~8.1s direct across adjacent lines), and ortho_check (~10s cumulative), not the tiny alpha/palette helpers. These are sampled estimates, not yet optimized or benchmarked. The full relief profile is still to be collected after the reporter fix.

…ior preparation (ZallaxDev#303)

Consolidate investigational branch onto integration after ZallaxDev#296.
Preserve output-equivalent Pillow/raster/interior changes and host tests.
Benchmark pinned integration against candidate with 1 and 4 building workers.
Keep draft until fresh paired hashes, proof checks, and timing results are reviewed.
@mkrieger95
mkrieger95 force-pushed the investigate/pillow-bulk-pixel-processing branch from 5d97cf0 to 64fff7f Compare November 22, 2026 02:35
Benchmarks passed in CI #913 after ZallaxDev#296: verified buildings
6.72% faster with one worker and 7.37% faster with four workers;
all generated asset SHA-256 hashes matched baseline.

Preserve pixel/geometry semantics regression tests, restore the existing
profiling helper, and drop one-off benchmark scripts and workflows.
No runtime or generator behavior changes.
@mkrieger95 mkrieger95 changed the title Draft: investigate Pillow bulk pixel and alpha-mask optimizations perf: accelerate verified voxel building image processing Nov 22, 2026
@mkrieger95
mkrieger95 marked this pull request as ready for review November 22, 2026 16:20
@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-22T16:20:52.753601Z
We couldn’t complete this review. Comment @codex review to try again.
5c5c433 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant