Repository navigation
Conversation
…ild 52 s -> 11 s, same output) ctest xdxr_build_check is 52 s of the 56 s Linux ctest step of every Runtime run. brute_force rounded every vertex to float32 again for each ray and triangle_test rebuilt the ray's axis permutation for each triangle. Scene keeps the rounded triangles and inverse transforms (lazily, so a masked-out instance is still never inverted); triangle_test is split into the per-ray and per-triangle parts with the same arithmetic in the same order. Output of check-build is byte-identical.
|
At Peak additional Python allocations on Windows 11 with CPython 3.14.7:
Save this as import sys, tracemalloc
from pathlib import Path
sys.path.insert(0,str(Path(sys.argv[1]).resolve()/'tools'))
from xdxr_bvh import brute_force
n=int(sys.argv[2])
tri=((0.,0.,0.),(1.,0.,0.),(0.,1.,0.))
raw=[(None,255,[tri]*n)]
tracemalloc.start()
hit=brute_force(raw,(2.,2.,-1.),(0.,0.,1.))
print(n, hit, tracemalloc.get_traced_memory()[1])Keep the cache for callers that pass a reusable AI-assisted. |
Kam471
left a comment
There was a problem hiding this comment.
Ran this at dc70f459 on Windows 11: pytest tests/test_xdxr_bvh.py -q -> 39 passed, 7 subtests passed; git diff --check clean.
brute_force now takes a Scene that rounds each instance's triangles to f32 and inverts its transform once (lazily, so a masked-out instance is still never touched), and hoists the ray's axis permutation/dd out of the triangle loop. The per-triangle arithmetic is the same operations in the same order with the early miss returns, so the comparison against the BVH keeps the old result; the tests include the tie/miss cases and a same-output check. No blocking issue.
|
Tested
No game files. Tested and written by Claude (Claude Code), posting from @theswiss24's account. |
…le at a time and keeps nothing (review: shdann)
|
Thanks @shdann, good catch: a one-off call paid for a cache it could never reuse. Taken as you suggested in cf4f317:
Thanks @theswiss24 and @Kam471 for the runs. AI-assisted (Claude Code). No game files. |
|
Tested What I ran:
Code review:
|
|
Tested cf4f317 merged with main 7b7d73f on WSL2 Ubuntu, Python 3.12.16: pass.
|
|
Tested cf4f317 on Windows 10 x64 19045 (RTX 5060 host, driver 617.42 for the
This machine is slower than the profiled pod (3.12 vs 3.13, and a laptop-class host), so the absolute numbers differ from the PR's table; the before/after ratio and the identical-output checks line up with it. |
# Conflicts: # tools/xdxr_bvh.py
|
Tested
No game files. AI-assisted (Claude Code). |
|
Independent Windows benchmark of
All six stdout captures are byte-identical (SHA-256 |
Claimed in the coordination issue as: new BUILD item, xdxr_bvh check-build speed (#4571 (comment))
Why
The Runtime workflow's
linux-gpu-toolsjob runsctest; on the last runs 52 s of its ~56 s are the single testxdxr_build_check(the same on a developer machine: 68 s of ctest, 52 s are this test). It is pure Python: for each of the 18 BVH cases it traces 1000 rays through the BVH and throughbrute_force, the reference that tests every triangle.Profile (cProfile, 146 s with the profiler on):
brute_forceis 138 s of it. It rounded every triangle vertex to float32 again for every ray (89 Mf32()calls, 50 s with the struct pack/unpack), andtriangle_testrebuilt the ray's axis permutation and several small lists for every one of 10 M triangle tests.The CI queue is the bottleneck right now (8 concurrent slots, see #4571), so runner minutes are what everyone waits for: this is ~40 s less on every Runtime run (about 2,000 completed runs a day on the last 24 h, ~1,300 runner-minutes a day), and 40 s less
ctestfor anyone who builds the runtime.What
brute_forcetakes aScene: the float32 rounding of each instance's triangles and its inverse transform are done once, the first time an instance is tested (so an instance the mask excludes is still never rounded or inverted), not once per ray. Passing the plain list still works, as before.triangle_testis split in two:_ray_axes(the ray's axis permutation, once per ray and instance) and_triangle_test(the same arithmetic, in the same order, with the three vertex loops unrolled and a miss returned as soon as the edge functions give one).triangle_test(v, org, d, remap)keeps its signature and result.check-buildandselftestbuild oneSceneper case instead of per ray.No change to what is checked: same rays, same triangles, same comparison.
Tested
On the RunPod pod (RTX 5080, Python 3.13), tree at
d0835dd9(main), the 18 casesvk_xdxr_build_testwrites:xdxr_bvh.py check-build <cases> --rays 1000, 3 runsrepr(so -0.0, 0.0 and NaN count as different): 300,000 randomtriangle_testcalls (ties, zeros, +-inf, NaN, 1e+-30, axis-aligned triangles, every remap byte) and 24,000brute_forcecalls (instances, masks, transforms, singular matrices, tmax, exceptions): 0 differ.python -I tests/test_xdxr_bvh.py: 39 tests OK (37 existing + 2 new: a reusedSceneanswers like a fresh one over 1,600 rays; a singular instance the mask excludes is still not inverted).xdxr_bvh.py selftestOK.Overlap: #3940 adds a
ties=keyword tobrute_force; the two merge by hand in a few lines (its loop would use_triangle_testthe same way).AI-assisted (Claude). No game files.