Repository navigation
Avoid tiny numpy arrays in numba: optimize arcs.py - #1895
Conversation
Locally I'm seeing grid.bounds speedup of roughly 5-20% (~30ms became ~25ms for a 28k faces example; ~1.72s became ~1.59s for a 2.6M faces examples). This is enough to confirm the changes in arcs.py helped with something at least a little bit! Not surprising that the speedup isn't huge though, there are still many more tiny numpy allocations occurring in bounds.py.
ASV BenchmarkingBenchmark Comparison ResultsBenchmarks that have improved:
Benchmarks that have stayed the same:
Benchmarks that have got worse:
|
|
Marking as ready for review - tests all passing and ASV suite roughly agrees with my expectations, i.e. maybe some small improvements to some |
cmdupuis3
left a comment
There was a problem hiding this comment.
-
Using
np.maxinstead ofmax3results in different NaN handling, is that intentional? -
extreme_gca_latitudeandextreme_gca_zstill callnp.iscloseon scalars. Under numba this is about 3x slower than an explicitabs(d - x) <= atolcomparison
I was aware that Python's
A few thoughts on this:
|
|
dylannelson
left a comment
There was a problem hiding this comment.
Compared to main and observed 0 bitwise differences in this update. The speedup was observed and not seeing any changes in functionality that break existing methods/usage. Looks good, thanks!
These were never affecting the result, since they were doing A = clip_scalar(A, 0, 1) followed by using the altered A if and only if 0 < A < 1. The clip only affects A when NOT 0 < A < 1.
Good point, I remember having a feeling before that those lines might not be doing much, and upon taking a closer look I agree with your assessment here. I removed the relevant lines and updated the PR overview message to mention this small expansion of scope. |
cmdupuis3
left a comment
There was a problem hiding this comment.
I'm seeing that replacing np.dot with _numba_dot3 results in a one ulp difference, so it doesn't reproduce main, but that's minor enough that I'm approving and merging
Closes #1894
Overview
Optimizes numba routines in
uxarray/grid/arcs.pyto avoid constructing many tiny numpy arrays inside numba routines, as discussed in #1648. Also updated call sites (in bounds.py) ofextreme_gca_latitude(which is defined in arcs.py) to utilize tuples instead of constructing tiny numpy arrays. Locally seeing ~5-20% speedup when constructing grid.bounds (excluding any cold-start numba compile time).Small expansions of scope:
_to_listhelper function which was not being used anywhere.max3andmin3helper functions; just use Python's max and min instead._orient3d_on_sphere_value_xyz; just use_orient3d_on_sphere_valueinstead.if isclose...: clip_scalar(...)code blocks.PR Checklist
General
Testing & Benchmarking
Documentation and Examples
docs/api.rst; internal (private) function names start with an underscore (_)AI Disclosure
AI Usage: mostly just GitHub Copilot's inline code suggestions; one tiny sanity check (about the max3 helper function) with Claude.