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

Open
opened 2026-11-26 20:17:38 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/315
Author: @Andretuta
Created: 11/24/2026
Status: 🔄 Open

Base: main ← Head: old-pr/10049


📝 Commits (1)

  • 24ac126 perf: read grass and prop instance lists in bulk in instance_lists

📊 Changes

3 files changed (+212 additions, -31 deletions)

View changed files

📝 docs/world.md (+5 -1)
📝 tests/test_instance_lists.py (+132 -0)
📝 tools/instance_lists.py (+75 -30)

📄 Description

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.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/315 **Author:** [@Andretuta](https://github.com/Andretuta) **Created:** 11/24/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `old-pr/10049` --- ### 📝 Commits (1) - [`24ac126`](https://github.com/ubiquitarianism/leonida/commit/24ac12684617f30e9d5bfe97d90150add2feedfc) perf: read grass and prop instance lists in bulk in instance_lists ### 📊 Changes **3 files changed** (+212 additions, -31 deletions) <details> <summary>View changed files</summary> 📝 `docs/world.md` (+5 -1) 📝 `tests/test_instance_lists.py` (+132 -0) 📝 `tools/instance_lists.py` (+75 -30) </details> ### 📄 Description > 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. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
starred/leonida#366
No description provided.