mirror of
https://github.com/ubiquitarianism/leonida.git
synced 2026-11-26 21:30:53 +01:00
[PR #2376] d16_format_probe: compute the rule models once per input (TEST-D16-MODELS-CACHE) #2379
Labels
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
starred/leonida#2379
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/ubiquitarianism/leonida/pull/2376
Author: @enlight3d
Created: 11/26/2026
Status: 🔄 Open
Base:
main← Head:test-d16-models-cache📝 Commits (1)
e6b97d1d16_format_probe: compute the rule models once per input📊 Changes
2 files changed (+33 additions, -10 deletions)
View changed files
📝
tests/test_d16_format_probe.py(+8 -0)📝
tools/d16_format_probe.py(+25 -10)📄 Description
Claimed in the coordination issue as: TEST-D16-MODELS-CACHE (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7197567323), picking up the item @amine23012004 claimed and then released as free for anyone (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7191191563).
What and why
models16()andmodels32()intools/d16_format_probe.pyare pure functions of (kind, bits, value), but a sweep,classify()and the tests call them about 955,000 times for about 131,000 distinct inputs, each time redoing the exactFractionarithmetic. The rule bits are now computed once per input (functools.lru_cacheon a tuple), and each call still returns a fresh dict, so a caller that edits it cannot change what the next call gets. Every caller looks the rules up by name (classify()iterates its ownrulestuple), so the dict's key order does not reach any output. No result changes.The commit is amine23012004's, kept as written and with them as its author (their branch
test-d16-models-cache, 9a7128947), rebased on currentmain. It adds a test that the cache hands each call its own dict.tests/semantic/test_buffer_load_format.pyandtools/rdna2spirv.pyonly name the probe in comments; nothing else imports it excepttools/d16_image_probe.pyand the two d16 test files.This PR touches the same two files as #1664; the two merge without conflict (
git merge-treeof both heads).Tested
On
main2e2c51c09+ this commit, Windows 11 (26300), Python 3.12.10, i9-13900K, timed while a fullmake_game.pybuild was using the CPU, so the absolute times are noisy:python -I tests/test_d16_format_probe.py: 26.6 s before, 12.0 s after (12.4 s after the rebase); 24 tests OK (2 skipped, GPU).python -I tests/test_d16_image_probe.py: 22.6 s before, 17.0 s after; OK (2 skipped).python -I tools/d16_format_probe.py --self-test: self-test ok.python -I tests/test_image_d16_probe.py: 22 tests OK (2 skipped).python -m unittest discover -s tests/semantic -p test_buffer_load_format.py: 34 tests OK.python -m compileall -q make_game.py tools tests,python -I make_game.py --help,python -I tests/test_text_write_line_endings.py(3 OK),python -I scripts/check_no_game_data.pyon both changed files,git diff --check: clean.amine23012004 measured 26.7 s -> 7.7 s and 21.8 s -> 13.1 s on an idle machine.
GPUs tested: n/a (CPU-only change; the probe's GPU kernels are untouched)
AI-assisted: yes (Claude Code)
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed. (No translator rule here.)🤖 Generated with Claude Code
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.