Repository navigation
Add batch line-of-sight queries to VisibilityChecker - #531
Conversation
pnxenopoulos
left a comment
There was a problem hiding this comment.
Thanks for identifying a great area to improve perf!
Added one small request r.e. error propagation on pool creation.
Once we get that in, we can release 3.2!
| .num_threads(threads) | ||
| .thread_name(|i| format!("awpy-visibility-{i}")) | ||
| .build() | ||
| .ok()?; |
There was a problem hiding this comment.
I believe this discards a pool-creation error (the .build().ok()? part)
So if one does
checker.is_visible_many(starts, ends, threads=2)and then say the OS cannot create the 2 thread pool, then the error becomes None which affects None => job() (ends up using Rayon's global pool)
I think the way to fix this is to simply propagate the pool-creation error. Maybe something like
let pool = rayon::ThreadPoolBuilder::new()
.num_threads(threads)
.thread_name(|i| format!("awpy-visibility-{i}"))
.build()
.map_err(|error| {
PyRuntimeError::new_err(format!(
"cannot create a visibility pool with {threads} threads: {error}"
))
})?;There was a problem hiding this comment.
Thanks! Fixed in 4e5c7ac: the pool is now looked up before the GIL is released, and a failed build raises RuntimeError (listed under Raises) instead of falling back to the global pool.
pnxenopoulos
left a comment
There was a problem hiding this comment.
These changes look good to me!
If you don't mind, under crates/awpy-python/docs/changelog.md can you start at the top a new header 3.2.0 and then add a line for your change?
|
Done in a649198. |
Adds
VisibilityChecker.is_visible_many(a, b, *, threads=None)andis_occluded_many. They check many segments per call and return a Booleanpolars.Series; each value equalsis_visible(a_i, b_i).Per-call overhead makes
is_visibleslow for workloads with millions of rays, such as per-tick visible areas (about 12M calls per round in my case).Changes
awpy: the BVH traversal moves into a privateoccluded_withwith a reusable stack, shared byis_occluded(behaviour unchanged) and the newVisibilityMesh::occluded_into(a, b, out). No threads, no new dependencies.is_visible_many/is_occluded_manytakefloat32orfloat64buffers (NumPy not required) or sequences of points;ais one shared start or one per segment. Work runs on a rayon pool with the GIL released;threads=1stays on the calling thread.rayon = "1.12"is added toawpy-pythononly; it is already inCargo.lockthrough polars.Validation
Bit for bit equal to an
is_visibleloop on de_anubis, de_inferno, de_nuke and de_mirage: 11M segments per map, including tangential cases (ends on triangles, segments in a triangle's plane, vertices, zero length), acrossfloat32/float64, thread counts, strided and list inputs. The scalaris_visibleis unchanged.Performance
Recorded batches of one real round (8,347 calls, 12.0M segments); i5-10400, 6 cores / 12 threads, Windows.
is_visibleloopis_visible_many,threads=1is_visible_many, defaultSpawning threads per call (
std::thread::scope) instead of a pool was about 25% slower here (6.7×).Notes
threads=Noneuses every core; passthreads=1inside a process pool that already uses every core.