Repository navigation
Conversation
… with Python fallback A dependency-free Rust cdylib runs the four per-item loops of --deep: the quadtree walk, the polygon chain, the obstacle volume pairs and the grid hash-table checks (value bijection, octree keys, inner payload words). tools/_navmesh_native.py loads it with ctypes; every call returns None, and navmesh_decode.py runs its unchanged Python reference, when the library is missing, fails to load, reports another ABI, declines the input, or LEONIDA_NAVMESH_NATIVE=0 is set. Counters are applied in first-seen order so the report is identical, key order included. tests/test_navmesh_native.py: 1,500 seeded synthetic cases per kernel, whole deep scans of an archive and a carved folder, edge cases, fallback (absent, unloadable, opted out, declined) and kernel timings (23x-107x). CI builds the crate and runs the parity tests with the library loaded. PERF-NAVMESH-NATIVE Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Overlap note: #8845 also edits |
|
Tested on Apple M1 Max, macOS 27.2.1 arm64, Python 3.12.16: |
|
Independent Linux validation at
I also combined this head locally with #8845 at No discrepancy found in this scope. The combined checkout is only an integration check, not a replacement implementation. Windows/macOS native builds and real resources remain untested here. |
Summary
tools/navmesh_native, a dependency-free Rustcdylib(empty[dependencies], std only) for the four per-item loops ofnavmesh_decode.py --deep:_walk_quadtree,_poly_chain, the pair loop of_walk_volumes, and the grid hash-table checks (_grid_values,_grid_slots,_grid_octree,_grid_payloads).tools/_navmesh_native.pyloads it withctypes. Every kernel fills a fixedu64array and allocates nothing the caller has to free. All reads are bounds-checked, so no input can make it panic.navmesh_decode.pygets a native fast path at the top of each of these functions (+34/−1 lines). The Python reference is unchanged and stays the specification. It runs when the library is missing, fails to load, reports another ABI, declines an input (an out-of-bounds block, anything other thanbytes, etc.), orLEONIDA_NAVMESH_NATIVE=0is set.--locked --offline), checks that the library loads, then runs the parity tests andtests/test_navmesh_decode.pywith the library loaded.Claimed in #8683 (claim comment) as PERF-NAVMESH-NATIVE. Built on
main, independent of my pure-Python #7059. If #6136 changes the water bit of the polygon chain, the mask is a parameter of the native call (0x80000today), and the parity test fails until the two agree.Performance
Windows 11 build 26300, CPython 3.12, rustc 1.100.0 release. The inputs are synthetic and built in the test. The table shows the best of several runs through the public functions, including the ctypes call and applying the stats in Python.
--deep, 60,000 slots (wholedecode_grid)End to end, a whole
scan(..., deep=True)gets less, because zlib inflate and the shallow header checks are untouched. On a synthetic archive of 60 tiles with 3,000 polygons each plus 150 grids, it drops from 175.9 ms to 125.6 ms (1.4×).Verification
cargo build --releaseandcargo test --release: 4 Rust tests pass. Both commands emit zero warnings, andcargo fmt --checkis clean.python -I tests/test_navmesh_native.py: 11 pass with the library loaded. The suite covers:MAX_QT_DEPTHandMAX_QT_NODESlimits.LEONIDA_NAVMESH_NATIVE=0, and a kernel that declines every call.tests/test_navmesh_decode.pypasses with the library loaded, withLEONIDA_NAVMESH_NATIVE=0, and with the DLL removed. In the last two runs the new suite passes its fallback tests and skips the 7 native ones.test_navmesh_links,test_navmesh_nodes,test_navmesh_tile_obj,test_navmesh_cell_fit,test_report_paths,test_report_path_caseandtest_zero_spanall pass.python -m compileall -q make_game.py tools tests,python -I tests/test_ci_registration.pyandpython -I scripts/check_no_game_data.pypass.AI-assisted (Claude Opus 5.5). All tests and benchmarks used synthetic data and ran on the CPU; no GPU is involved.
🤖 Generated with Claude Code