instance_lists: count grass and prop instances in bulk (9x / 3.6x, same output) #315

Open
github-bot wants to merge 1 commit from github-bot/gh-315 into main AGit
Owner

@⁠Andretuta on GitHub · 2026-11-24 03:07 UTC · original
ubiquitarianism:old-pr/10049 → main · +212 −31 · 3 files · 1 commits · draft

Carried over from old PR 10049 by tedin7 in the original Leonida repository, which went private on 23 Nov 2026. The code is the branch old-pr/10049, exactly that PR's last commit. All carried-over PRs are listed in #17.
Opened as a draft, and the CI runs the opening started were cancelled so 250 PRs don't fill the queue. Re-run CI here when you review it.
tedin7: this is your work. Feel free to take it over, by pushing to the branch or opening your own PR and closing this one.


Original description (mentions and #N references are disabled; the numbers refer to the old repository):

@ItsNotRexed: an exe PR, as you asked.

What

tools/instance_lists.py counts prop and grass instances (hundreds of millions over the full corpus) one record at a time in Python. This reads them in bulk instead:

  • grass: each byte field is one strided slice; (NormalX, NormalY) pairs are counted once per distinct pair, ScaleZ == Scale is one XOR of two columns, Scale == 0 and the rotation max are bytes.count / max.
  • props: each 3x4 matrix comes out of one Struct.iter_unpack pass, with local counters instead of eight dict updates per instance.
  • Truncation (record past the end of the buffer, member offset below 0) is computed up front with the same prefix semantics as the old break.

Output is identical. tools/world_build.py and tools/sandbox_scene.py do not read these lists (they take entity placements), so I left them alone; docs/world.md says so and gives the numbers.

Why

A list holds at most 65,535 instances (u16 count), so memory was never the problem: one resource plus its joined streams. Time was: the full corpus is about 225 M grass and 26 M prop instances at roughly 1.4 us and 12 us each in Python.

Tested

Synthetic bytes only, no game file.

  • Synthetic 65,535-instance list, best of 3: grass 0.091 s to 0.010 s (9x), props 0.815 s to 0.224 s (3.6x); the full counts dict is equal to the old module's for both.
  • New tests in tests/test_instance_lists.py: grass and prop counts equal a record-by-record oracle on seeded random data, including NaN/zero matrices and buffers cut mid-list (5 + 3 cases); a speed test needs bulk at least 4x faster than the oracle on near-upright grass normals.
  • Negative control: with the old instance_lists.py the speed test fails (bulk 0.0915 s vs 0.0719 s); with the change all 19 tests pass, and tests/test_instance_lists_schema_gap.py still passes.
**@⁠Andretuta** on GitHub · 2026-11-24 03:07 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/315) `ubiquitarianism:old-pr/10049` → `main` · +212 −31 · 3 files · 1 commits · draft > Carried over from **old PR 10049** by `tedin7` in the original Leonida repository, which went private on 23 Nov 2026. The code is the branch `old-pr/10049`, exactly that PR's last commit. All carried-over PRs are listed in #17. > Opened as a draft, and the CI runs the opening started were cancelled so 250 PRs don't fill the queue. Re-run CI here when you review it. > `tedin7`: this is your work. Feel free to take it over, by pushing to the branch or opening your own PR and closing this one. --- Original description (mentions and `#N` references are disabled; the numbers refer to the old repository): `@ItsNotRexed`: an exe PR, as you asked. ## What `tools/instance_lists.py` counts prop and grass instances (hundreds of millions over the full corpus) one record at a time in Python. This reads them in bulk instead: - grass: each byte field is one strided slice; (NormalX, NormalY) pairs are counted once per distinct pair, ScaleZ == Scale is one XOR of two columns, Scale == 0 and the rotation max are `bytes.count` / `max`. - props: each 3x4 matrix comes out of one `Struct.iter_unpack` pass, with local counters instead of eight dict updates per instance. - Truncation (record past the end of the buffer, member offset below 0) is computed up front with the same prefix semantics as the old `break`. Output is identical. `tools/world_build.py` and `tools/sandbox_scene.py` do not read these lists (they take entity placements), so I left them alone; `docs/world.md` says so and gives the numbers. ## Why A list holds at most 65,535 instances (u16 count), so memory was never the problem: one resource plus its joined streams. Time was: the full corpus is about 225 M grass and 26 M prop instances at roughly 1.4 us and 12 us each in Python. ## Tested Synthetic bytes only, no game file. - Synthetic 65,535-instance list, best of 3: grass 0.091 s to 0.010 s (9x), props 0.815 s to 0.224 s (3.6x); the full counts dict is equal to the old module's for both. - New tests in `tests/test_instance_lists.py`: grass and prop counts equal a record-by-record oracle on seeded random data, including NaN/zero matrices and buffers cut mid-list (5 + 3 cases); a speed test needs bulk at least 4x faster than the oracle on near-upright grass normals. - Negative control: with the old `instance_lists.py` the speed test fails (bulk 0.0915 s vs 0.0719 s); with the change all 19 tests pass, and `tests/test_instance_lists_schema_gap.py` still passes.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 08:53:06 +00:00
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/315/head:github-bot/gh-315'
git switch 'github-bot/gh-315'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-315'
git switch 'github-bot/gh-315'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-315'
git switch 'github-bot/gh-315'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-315'
git switch 'main'
git merge --squash 'github-bot/gh-315'
git switch 'main'
git merge --ff-only 'github-bot/gh-315'
git switch 'main'
git merge 'github-bot/gh-315'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.