Skip to content

Avoid tiny numpy arrays in numba: optimize bounds.py and pole_point_inside_polygon - #1929

Open
Sevans711 wants to merge 10 commits into
mainfrom
sevans/tinynumpynumba-optimize-bounds.py
Open

Sevans711 wants to merge 10 commits into
mainfrom
sevans/tinynumpynumba-optimize-bounds.py

Conversation

@Sevans711

@Sevans711 Sevans711 commented Dec 1, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #1896

Overview

Optimizes numba routines in uxarray/grid/bounds.py to avoid constructing many tiny numpy arrays inside numba routines, as discussed in #1648. I expect results should be bit-for-bit identical even after these changes.

Similarly, optimizes pole_point_inside_polygon (from geometry.py) by avoiding many tiny numpy arrays, because it is used inside bounds.py methods. This is a large expansion of scope, but it makes a noticeable difference. In my 150k faces example, I was seeing ~140ms for grid.bounds on main, ~90ms for grid.bounds after the bounds.py optimizations alone, and ~70ms after incorporating the pole_point_inside_polygon optimizations as well. Many of the pole_point_inside_polygon changes were cherry-picked from commits in #1790, which sought to similarly optimize geometry.py but isn't yet finished/merged.

Performance improvements:

  • Locally I saw roughly 2x speedup in grid.bounds computations on an example grid with 150k faces.
  • ASV shows a similar speedup (not much improvement for the fastest/smallest case, but more speedup for slower/larger cases with the slowest one showing a ratio of ~0.55).
  • ASV also shows roughly 2x reduction in peakmem usage.

Nontrivial / "slightly surprising" changes (but, all within the original scope):

  • Refactored some methods to use nodes_idx, node_x, node_y, and node_z, (and node_lon and node_lat) instead of face_edges_xyz (and face_edges_lonlat). This refactor is similar to how PR Speeds up to_raster() by improving efficiency of Grid.get_faces_containing_point() #1809 swapped from _face_contains_point with input face_edges to _point_in_face with input nodes_idx, node_x, node_y, and node_z. That PR writeup explains in more detail, but the basic idea is just that rewriting the relevant indexing logic enables avoiding the construction of many tiny face_edges arrays. This affects:
    • _construct_face_bounds
      • Also removed the now-unused _get_cartesian_face_edge_nodes and _get_spherical_face_edge_nodes helper methods.
    • pole_point_inside_polygon
    • _check_intersection
      • Also renamed this method to a more descriptive name: _check_pole_ref_edge_intersection.
  • Further refactored _check_pole_ref_edge_intersection to use hemisphere_filter internally, to avoid building the tiny arrays north_edges_xyz and south_edges_xyz inside pole_point_inside_polygon.
  • Updated extreme_gca_latitude to include a few np.float64() conversions. Inputs at all internal call sites previously were already float64, but the refactor above led to float32 inputs sometimes (whenever node_x, etc were stored in float32, which can occur by default). Upcasting to float64 ensures higher precision math (and allows bit-for-bit match to results on main).

Small expansions of scope:

  • removed the any_close_lat and all_elements_nan helper functions which were each only being used in one location.
  • updated _point_in_face docstring to avoid incorrect implication that nodes_idx has same shape as node_x, node_y, and node_z.

Misc. note:

  • It would be highly nontrivial (if possible at all) to entirely avoid allocating the tiny intersection_points array while keeping exactly equivalent uniqueness tests during _unique_points(), inside _check_pole_ref_edge_intersection. However, when checking on a 150k faces grid with intersection_points == 0 always, even when I commented out all pieces of the code relevant to these allocations and the uniqueness checks, the speedup was only ~1%. This suggests that keeping the allocation inside the logical branch where it is now is already very close to optimal, it doesn't prevent any significant numba LLVM optimizations, and it's probably not worthwhile to optimize further.

PR Checklist

General

  • An issue is created and linked
  • Added appropriate labels (if your uxarray repo permissions allow it)
  • Filled out Overview and Expected Usage (if applicable) sections

Testing & Benchmarking

  • There is adequate test coverage of changes from this PR (add new tests if needed)
  • If this PR could affect performance, ran ASV benchmarks and confirmed they show expected behavior (add a new benchmark if necessary)

Documentation and Examples

  • Docstrings updated with any function changes, and included in all new functions
  • User (public) functions added to docs/api.rst; internal (private) function names start with an underscore (_)
  • [N/A] If touched any notebook files, cleared the output of all cells before committing
  • [N/A] If added new notebook files, put into appropriate directories and referenced in appropriate files

AI Disclosure

AI Usage: Claude for some debugging, test suite updates, and later rounds of optimizations, but initial rounds of optimizations here were done without Claude. Also used Github Copilot inline coding suggestions.

  • I have tested and take responsibility for all AI-generated content in my PR.

Locally seeing a small speedup from this, in grid.bounds: 140±5 ms --> 127±1 ms, for a grid with 150k faces.

Also removes small only-used-once helper functions `any_close_lat` and `all_elements_nan`, inlining the relevant logic instead.
No noticeable effect on speed from this particular commit, which is unsurprising because it only affects the ``if has_north_pole or has_south_pole`` path.
Seeing a pretty significant speedup locally now; grid.bounds for the same grid as in d75fed0 is down to 89 ± 2ms (from 140 ± 5 ms on main).

One (significant) improvement remains possible: refactoring pole_point_in_polygon to use nodes_idx instead of face_edges would allow _construct_face_bounds to entirely avoid tiny numpy arrays.

For "nodes_idx versus face_edges" explanation, see PR #1809.

Still need to update test suite appropriately for the new syntax here.
cherry picked directly from older geometry.py optimizations attempt (see #1790). This commit is just the cherry pick, plus resolving some conflicts (with imports) and applying updated ruff formatting.

More speedup: grid.bounds for the same grid as in d75fed0 is down to 78 ± 2ms (from 140 ± 5 ms on main, and 89 ± 2ms on f5ca4a4), and still bit-for-bit identical.

(cherry picked from commit f3c4e22)
After the latest commit, face_edges_lonlat is now unused in _construct_face_bounds because it is unused in pole_point_inside_polygon. Removing it makes a tiny speedup compared to previous commit; 78 ± 2ms --> 75 ± 2ms on the example grid I've been testing.
This makes a small speedup compared to the previous commit, 75 ± 2ms --> 71 ± 1ms on the example grid I've been testing.
tiny speedup, only ~1-2 ms faster than previous commit's 71 ± 1ms, on the example grid I've been using.

My example grid has no pole points, so as a sanity check I also tried having pole_point_inside_polygon just return False. That showed 48 ± 1ms,  i.e. pole_point_inside_polygon optimizations alone cannot bring the speed lower than that.
The bug was introduced recently, in commit 3cd6a5e.
@Sevans711 Sevans711 added scalability Related to scalability & performance efforts run-benchmark Run ASV benchmark workflow labels Dec 1, 2026
@github-actions

github-actions Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

ASV Benchmarking

Benchmark Comparison Results

Benchmarks that have improved:

Change Before [0e6c231] After [92a3f31] Ratio Benchmark (Parameter)
- 1.72M 754k 0.44 face_bounds.FaceBounds.track_peakmem_face_bounds(PosixPath('/home/runner/work/uxarray/uxarray/test/meshfiles/mpas/QU/oQU480.231010.nc'))
- 1.7M 734k 0.43 face_bounds.FaceBounds.track_peakmem_face_bounds(PosixPath('/home/runner/work/uxarray/uxarray/test/meshfiles/scrip/outCSne8/outCSne8.nc'))
- 1.86M 896k 0.48 face_bounds.FaceBounds.track_peakmem_face_bounds(PosixPath('/home/runner/work/uxarray/uxarray/test/meshfiles/ugrid/geoflow-small/grid.nc'))
- 2.1M 1.05M 0.5 subset.BoundingBoxHealpix.track_peakmem_bounding_box(6)

Benchmarks that have stayed the same:

Change Before [0e6c231] After [92a3f31] Ratio Benchmark (Parameter)
955±10μs 967±10μs 1.01 connectivity.Connectivity.time_edge_face('120km')
453±10μs 457±10μs 1.01 connectivity.Connectivity.time_edge_face('480km')
3.84±0.02ms 3.85±0.02ms 1.00 connectivity.Connectivity.time_edge_node('120km')
1.23±0.04ms 1.22±0.02ms 1.00 connectivity.Connectivity.time_edge_node('480km')
61.1±2μs 63.2±8μs 1.03 connectivity.Connectivity.time_face_edge('120km')
61.1±8μs 65.0±8μs 1.06 connectivity.Connectivity.time_face_edge('480km')
970±30μs 959±10μs 0.99 connectivity.Connectivity.time_face_face('120km')
396±30μs 398±10μs 1.00 connectivity.Connectivity.time_face_face('480km')
63.4±9μs 59.7±2μs 0.94 connectivity.Connectivity.time_face_node('120km')
59.0±8μs 59.4±4μs 1.01 connectivity.Connectivity.time_face_node('480km')
476±100μs 474±30μs 0.99 connectivity.Connectivity.time_n_nodes_per_face('120km')
385±20μs 386±20μs 1.00 connectivity.Connectivity.time_n_nodes_per_face('480km')
1.34±0.02ms 1.40±0.02ms 1.04 connectivity.Connectivity.time_node_edge('120km')
459±8μs 474±3μs 1.03 connectivity.Connectivity.time_node_edge('480km')
87.9±0.8ms 90.6±2ms 1.03 connectivity.Connectivity.time_node_face('120km')
5.67±0.04ms 5.76±0.06ms 1.02 connectivity.Connectivity.time_node_face('480km')
1.42M 1.42M 1.00 connectivity.ConnectivityTracemalloc.track_peakmem_edge_face('120km')
105k 105k 1.00 connectivity.ConnectivityTracemalloc.track_peakmem_edge_face('480km')
6.48M 6.48M 1.00 connectivity.ConnectivityTracemalloc.track_peakmem_edge_node('120km')
419k 419k 1.00 connectivity.ConnectivityTracemalloc.track_peakmem_edge_node('480km')
2.05k 2.05k 1.00 connectivity.ConnectivityTracemalloc.track_peakmem_face_edge('120km')
2.05k 2.05k 1.00 connectivity.ConnectivityTracemalloc.track_peakmem_face_edge('480km')
1.6M 1.6M 1.00 connectivity.ConnectivityTracemalloc.track_peakmem_face_face('120km')
101k 101k 1.00 connectivity.ConnectivityTracemalloc.track_peakmem_face_face('480km')
2.18k 2.18k 1.00 connectivity.ConnectivityTracemalloc.track_peakmem_face_node('120km')
2.18k 2.18k 1.00 connectivity.ConnectivityTracemalloc.track_peakmem_face_node('480km')
240k 240k 1.00 connectivity.ConnectivityTracemalloc.track_peakmem_n_nodes_per_face('120km')
26k 26k 1.00 connectivity.ConnectivityTracemalloc.track_peakmem_n_nodes_per_face('480km')
1.9M 1.9M 1.00 connectivity.ConnectivityTracemalloc.track_peakmem_node_edge('120km')
127k 127k 1.00 connectivity.ConnectivityTracemalloc.track_peakmem_node_edge('480km')
11.9M 11.9M 1.00 connectivity.ConnectivityTracemalloc.track_peakmem_node_face('120km')
747k 747k 1.00 connectivity.ConnectivityTracemalloc.track_peakmem_node_face('480km')
6.33±0.5ms 4.33±0.09ms ~0.68 face_bounds.FaceBounds.time_face_bounds(PosixPath('/home/runner/work/uxarray/uxarray/test/meshfiles/mpas/QU/oQU480.231010.nc'))
2.22±0.2ms 1.70±0.03ms ~0.77 face_bounds.FaceBounds.time_face_bounds(PosixPath('/home/runner/work/uxarray/uxarray/test/meshfiles/scrip/outCSne8/outCSne8.nc'))
7.23±7ms 3.96±4ms ~0.55 face_bounds.FaceBounds.time_face_bounds(PosixPath('/home/runner/work/uxarray/uxarray/test/meshfiles/ugrid/geoflow-small/grid.nc'))
1.25±0.02ms 1.22±0.02ms 0.98 face_bounds.FaceBounds.time_face_bounds(PosixPath('/home/runner/work/uxarray/uxarray/test/meshfiles/ugrid/quad-hexagon/grid.nc'))
57.3k 57.3k 1.00 face_bounds.FaceBounds.track_nbytes_face_bounds(PosixPath('/home/runner/work/uxarray/uxarray/test/meshfiles/mpas/QU/oQU480.231010.nc'))
12.3k 12.3k 1.00 face_bounds.FaceBounds.track_nbytes_face_bounds(PosixPath('/home/runner/work/uxarray/uxarray/test/meshfiles/scrip/outCSne8/outCSne8.nc'))
123k 123k 1.00 face_bounds.FaceBounds.track_nbytes_face_bounds(PosixPath('/home/runner/work/uxarray/uxarray/test/meshfiles/ugrid/geoflow-small/grid.nc'))
128 128 1.00 face_bounds.FaceBounds.track_nbytes_face_bounds(PosixPath('/home/runner/work/uxarray/uxarray/test/meshfiles/ugrid/quad-hexagon/grid.nc'))
1.27M 1.27M 1.00 face_bounds.FaceBounds.track_nbytes_grid_with_bounds(PosixPath('/home/runner/work/uxarray/uxarray/test/meshfiles/mpas/QU/oQU480.231010.nc'))
50.1k 50.1k 1.00 face_bounds.FaceBounds.track_nbytes_grid_with_bounds(PosixPath('/home/runner/work/uxarray/uxarray/test/meshfiles/scrip/outCSne8/outCSne8.nc'))
516k 516k 1.00 face_bounds.FaceBounds.track_nbytes_grid_with_bounds(PosixPath('/home/runner/work/uxarray/uxarray/test/meshfiles/ugrid/geoflow-small/grid.nc'))
712 712 1.00 face_bounds.FaceBounds.track_nbytes_grid_with_bounds(PosixPath('/home/runner/work/uxarray/uxarray/test/meshfiles/ugrid/quad-hexagon/grid.nc'))
35.3k 35.3k 1.00 face_bounds.FaceBounds.track_peakmem_face_bounds(PosixPath('/home/runner/work/uxarray/uxarray/test/meshfiles/ugrid/quad-hexagon/grid.nc'))
823±50ns 792±60ns 0.96 geometry_kernels.AccucrossKernels.time_accucross
1.82±0.04μs 1.84±0.06μs 1.01 geometry_kernels.AccucrossKernels.time_accucross_pair
427±20ns 320±40ns ~0.75 geometry_kernels.EFTPrimitives.time_acc_sqrt_re
332±20ns 334±40ns 1.01 geometry_kernels.EFTPrimitives.time_diff_of_products
330±30ns 351±30ns 1.07 geometry_kernels.EFTPrimitives.time_two_prod
346±30ns 294±50ns ~0.85 geometry_kernels.EFTPrimitives.time_two_sum
513±30ns 530±20ns 1.03 geometry_kernels.GCAConstLatIntersection.time_accux_constlat_kernel
657±50ns 621±20ns 0.94 geometry_kernels.GCAConstLatIntersection.time_gca_const_lat_intersection
715±30ns 638±40ns ~0.89 geometry_kernels.GCAConstLatIntersection.time_try_gca_const_lat_intersection
821±40ns 871±30ns 1.06 geometry_kernels.GCAGCAIntersection.time_accux_gca_kernel
952±30ns 982±20ns 1.03 geometry_kernels.GCAGCAIntersection.time_gca_gca_intersection
1.05±0.05μs 1.12±0.01μs 1.07 geometry_kernels.GCAGCAIntersection.time_try_gca_gca_intersection
31.3±0.9μs 33.1±0.3μs 1.06 geometry_kernels.OrientPredicates.time_on_minor_arc
32.3±0.8μs 33.9±0.7μs 1.05 geometry_kernels.OrientPredicates.time_orient3d_on_sphere
3.10±0.04ms 3.08±0ms 0.99 geometry_samebody.SameBodyConstLat.time_accux_dispatch
1.16±0ms 1.16±0ms 1.00 geometry_samebody.SameBodyConstLat.time_accux_kernel
2.18±0.03ms 2.16±0ms 0.99 geometry_samebody.SameBodyConstLat.time_fp64_dispatch
148±0.1μs 148±1μs 1.00 geometry_samebody.SameBodyConstLat.time_fp64_kernel
37.9±0.04ms 38.1±0.1ms 1.00 geometry_samebody_gcagca.SameBodyGcaGca.time_accux_dispatch
4.10±0ms 4.17±0.02ms 1.02 geometry_samebody_gcagca.SameBodyGcaGca.time_accux_kernel
35.1±0.2ms 34.6±0.01ms 0.99 geometry_samebody_gcagca.SameBodyGcaGca.time_fp64_dispatch
492±8μs 508±10μs 1.03 geometry_samebody_gcagca.SameBodyGcaGca.time_fp64_kernel
933±10ms 931±10ms 1.00 import.Imports.timeraw_import_uxarray
1 1 1.00 lazy_grid_construction.LazyGridConstruction.track_computes_isel
3 3 1.00 lazy_grid_construction.LazyGridConstruction.track_computes_open_grid_chunked
113±2ms 112±3ms 0.99 lazy_grid_construction.OpenGridChunked.time_open_grid('120km')
144±2ms 143±3ms 0.99 lazy_grid_construction.OpenGridChunked.time_open_grid('480km')
3.32M 3.42M 1.03 lazy_grid_construction.OpenGridChunked.track_peakmem_open_grid('120km')
2.42M 2.22M 0.92 lazy_grid_construction.OpenGridChunked.track_peakmem_open_grid('480km')
1.71±0.01ms 1.70±0.01ms 1.00 mpas_ocean.AzimuthalAverage.time_azimuthal_average('120km')
761±7μs 745±8μs 0.98 mpas_ocean.AzimuthalAverage.time_azimuthal_average('480km')
2.06±0.05ms 1.97±0.01ms 0.96 mpas_ocean.CheckNorm.time_check_norm('120km')
1.55±0.04ms 1.51±0.03ms 0.98 mpas_ocean.CheckNorm.time_check_norm('480km')
796±10μs 780±4μs 0.98 mpas_ocean.ConnectivityConstruction.time_face_face_connectivity('120km')
351±10μs 349±4μs 0.99 mpas_ocean.ConnectivityConstruction.time_face_face_connectivity('480km')
492±7μs 483±20μs 0.98 mpas_ocean.ConnectivityConstruction.time_n_nodes_per_face('120km')
388±8μs 390±8μs 1.00 mpas_ocean.ConnectivityConstruction.time_n_nodes_per_face('480km')
4.79±0.02ms 4.78±0.01ms 1.00 mpas_ocean.ConstructFaceLatLon.time_cartesian_averaging('120km')
3.23±0.08ms 3.17±0.01ms 0.98 mpas_ocean.ConstructFaceLatLon.time_cartesian_averaging('480km')
104±0.8ms 103±0.7ms 1.00 mpas_ocean.ConstructFaceLatLon.time_welzl('120km')
9.40±0.2ms 9.28±0.1ms 0.99 mpas_ocean.ConstructFaceLatLon.time_welzl('480km')
9.76±0.01ms 9.73±0.02ms 1.00 mpas_ocean.ConstructTreeStructures.time_ball_tree('120km')
601±10μs 589±20μs 0.98 mpas_ocean.ConstructTreeStructures.time_ball_tree('480km')
7.00±0.05ms 6.95±0.02ms 0.99 mpas_ocean.ConstructTreeStructures.time_kd_tree('120km')
430±10μs 419±10μs 0.98 mpas_ocean.ConstructTreeStructures.time_kd_tree('480km')
623±5ms 607±4ms 0.97 mpas_ocean.CrossSections.time_const_lat('120km', 1)
312±7ms 307±3ms 0.99 mpas_ocean.CrossSections.time_const_lat('120km', 2)
159±3ms 156±0.6ms 0.98 mpas_ocean.CrossSections.time_const_lat('120km', 4)
564±4ms 574±5ms 1.02 mpas_ocean.CrossSections.time_const_lat('480km', 1)
282±2ms 280±2ms 0.99 mpas_ocean.CrossSections.time_const_lat('480km', 2)
148±3ms 145±1ms 0.98 mpas_ocean.CrossSections.time_const_lat('480km', 4)
21.2±0.07ms 21.2±0.04ms 1.00 mpas_ocean.DualMesh.time_dual_mesh_construction('120km')
2.40±0.01ms 2.48±0.2ms 1.04 mpas_ocean.DualMesh.time_dual_mesh_construction('480km')
7.90±0.2ms 7.90±0.2ms 1.00 mpas_ocean.FaceAreas.time_face_areas('120km')
2.58±0.1ms 2.57±0.1ms 1.00 mpas_ocean.FaceAreas.time_face_areas('480km')
229k 229k 1.00 mpas_ocean.FaceAreas.track_nbytes_face_areas('120km')
14.3k 14.3k 1.00 mpas_ocean.FaceAreas.track_nbytes_face_areas('480km')
2.12M 2.12M 1.00 mpas_ocean.FaceAreas.track_peakmem_face_areas('120km')
679k 679k 1.00 mpas_ocean.FaceAreas.track_peakmem_face_areas('480km')
52.0±0.8ms 53.4±0.9ms 1.03 mpas_ocean.GeoDataFrame.time_to_geodataframe('120km', 'exclude')
140±1ms 137±2ms 0.97 mpas_ocean.GeoDataFrame.time_to_geodataframe('120km', 'split')
4.69±0.3ms 5.00±0.3ms 1.07 mpas_ocean.GeoDataFrame.time_to_geodataframe('480km', 'exclude')
25.7±0.6ms 25.3±0.4ms 0.98 mpas_ocean.GeoDataFrame.time_to_geodataframe('480km', 'split')
9.26±0.1ms 9.15±0.02ms 0.99 mpas_ocean.Gradient.time_gradient('120km')
1.62±0.01ms 1.61±0.01ms 1.00 mpas_ocean.Gradient.time_gradient('480km')
457k 457k 1.00 mpas_ocean.Gradient.track_nbytes_gradient('120km')
28.7k 28.7k 1.00 mpas_ocean.Gradient.track_nbytes_gradient('480km')
3.44M 3.44M 1.00 mpas_ocean.Gradient.track_peakmem_gradient('120km')
226k 226k 1.00 mpas_ocean.Gradient.track_peakmem_gradient('480km')
326±20μs 323±10μs 0.99 mpas_ocean.HoleEdgeIndices.time_construct_hole_edge_indices('120km')
111±1μs 112±0.4μs 1.01 mpas_ocean.HoleEdgeIndices.time_construct_hole_edge_indices('480km')
185±2μs 201±8μs 1.09 mpas_ocean.Integrate.time_integrate('120km')
167±5μs 186±10μs ~1.12 mpas_ocean.Integrate.time_integrate('480km')
18.4M 18.4M 1.00 mpas_ocean.Integrate.track_nbytes_integrate('120km')
1.2M 1.2M 1.00 mpas_ocean.Integrate.track_nbytes_integrate('480km')
80.2±0.5ms 80.4±0.8ms 1.00 mpas_ocean.MatplotlibConversion.time_dataarray_to_polycollection('120km', 'exclude')
80.2±0.4ms 80.1±0.6ms 1.00 mpas_ocean.MatplotlibConversion.time_dataarray_to_polycollection('120km', 'include')
80.6±0.6ms 79.6±0.9ms 0.99 mpas_ocean.MatplotlibConversion.time_dataarray_to_polycollection('120km', 'split')
6.04±0.03ms 6.03±0.03ms 1.00 mpas_ocean.MatplotlibConversion.time_dataarray_to_polycollection('480km', 'exclude')
6.14±0.02ms 6.12±0.09ms 1.00 mpas_ocean.MatplotlibConversion.time_dataarray_to_polycollection('480km', 'include')
6.05±0.04ms 6.02±0.02ms 1.00 mpas_ocean.MatplotlibConversion.time_dataarray_to_polycollection('480km', 'split')
264±2ms 262±2ms 1.00 mpas_ocean.NeighborhoodBuild.time_build('120km', 1.0)
543±2ms 541±3ms 1.00 mpas_ocean.NeighborhoodBuild.time_build('120km', 5.0)
14.1±0.09ms 14.0±0.03ms 0.99 mpas_ocean.NeighborhoodBuild.time_build('480km', 1.0)
17.5±0.06ms 17.3±0.04ms 0.99 mpas_ocean.NeighborhoodBuild.time_build('480km', 5.0)
256±0.5ms 259±1ms 1.01 mpas_ocean.NeighborhoodBuild.time_query_radius('120km', 1.0)
537±3ms 535±1ms 1.00 mpas_ocean.NeighborhoodBuild.time_query_radius('120km', 5.0)
13.6±0.02ms 13.6±0.02ms 1.00 mpas_ocean.NeighborhoodBuild.time_query_radius('480km', 1.0)
17.1±0.1ms 17.0±0.08ms 1.00 mpas_ocean.NeighborhoodBuild.time_query_radius('480km', 5.0)
612.76 612.76 1.00 mpas_ocean.NeighborhoodBuild.track_mean_neighbors('120km', 15.0)
74.17 74.17 1.00 mpas_ocean.NeighborhoodBuild.track_mean_neighbors('120km', 5.0)
37.29 37.29 1.00 mpas_ocean.NeighborhoodBuild.track_mean_neighbors('480km', 15.0)
6.57 6.57 1.00 mpas_ocean.NeighborhoodBuild.track_mean_neighbors('480km', 5.0)
141M 141M 1.00 mpas_ocean.NeighborhoodBuild.track_nbytes_neighbors('120km', 15.0)
17.4M 17.4M 1.00 mpas_ocean.NeighborhoodBuild.track_nbytes_neighbors('120km', 5.0)
563k 563k 1.00 mpas_ocean.NeighborhoodBuild.track_nbytes_neighbors('480km', 15.0)
123k 123k 1.00 mpas_ocean.NeighborhoodBuild.track_nbytes_neighbors('480km', 5.0)
145M 145M 1.00 mpas_ocean.NeighborhoodBuild.track_peakmem_build('120km', 15.0)
21.5M 21.5M 1.00 mpas_ocean.NeighborhoodBuild.track_peakmem_build('120km', 5.0)
824k 824k 1.00 mpas_ocean.NeighborhoodBuild.track_peakmem_build('480km', 15.0)
384k 384k 1.00 mpas_ocean.NeighborhoodBuild.track_peakmem_build('480km', 5.0)
28.9±1ms 28.9±0.3ms 1.00 mpas_ocean.NeighborhoodDask.time_mean('120km', 'grid_chunks')
13.8±0.1ms 13.7±0.2ms 0.99 mpas_ocean.NeighborhoodDask.time_mean('120km', 'numpy')
26.4±0.6ms 26.2±0.5ms 0.99 mpas_ocean.NeighborhoodDask.time_mean('120km', 'time_chunks')
7.47±0.09ms 7.37±0.06ms 0.99 mpas_ocean.NeighborhoodDask.time_mean('480km', 'grid_chunks')
442±4μs 437±3μs 0.99 mpas_ocean.NeighborhoodDask.time_mean('480km', 'numpy')
5.11±0.07ms 5.05±0.09ms 0.99 mpas_ocean.NeighborhoodDask.time_mean('480km', 'time_chunks')
5.82M 5.83M 1.00 mpas_ocean.NeighborhoodDask.track_peakmem_mean('120km', 'grid_chunks')
2.75M 2.75M 1.00 mpas_ocean.NeighborhoodDask.track_peakmem_mean('120km', 'numpy')
5.67M 5.68M 1.00 mpas_ocean.NeighborhoodDask.track_peakmem_mean('120km', 'time_chunks')
669k 677k 1.01 mpas_ocean.NeighborhoodDask.track_peakmem_mean('480km', 'grid_chunks')
177k 177k 1.00 mpas_ocean.NeighborhoodDask.track_peakmem_mean('480km', 'numpy')
520k 534k 1.03 mpas_ocean.NeighborhoodDask.track_peakmem_mean('480km', 'time_chunks')
4.85±0s 4.85±0.01s 1.00 mpas_ocean.NeighborhoodReduce.time_dataset_reduce('120km', 'mean')
4.99±0.01s 4.99±0s 1.00 mpas_ocean.NeighborhoodReduce.time_dataset_reduce('120km', 'median')
126±0.6ms 126±0.7ms 1.00 mpas_ocean.NeighborhoodReduce.time_dataset_reduce('480km', 'mean')
128±0.1ms 128±0.2ms 1.00 mpas_ocean.NeighborhoodReduce.time_dataset_reduce('480km', 'median')
544±3ms 545±3ms 1.00 mpas_ocean.NeighborhoodReduce.time_neighborhood_reduce('120km', 'mean')
579±2ms 582±3ms 1.01 mpas_ocean.NeighborhoodReduce.time_neighborhood_reduce('120km', 'median')
17.7±0.1ms 17.5±0.04ms 0.99 mpas_ocean.NeighborhoodReduce.time_neighborhood_reduce('480km', 'mean')
18.1±0.01ms 17.8±0.04ms 0.98 mpas_ocean.NeighborhoodReduce.time_neighborhood_reduce('480km', 'median')
4.96±0.02ms 4.88±0.01ms 0.98 mpas_ocean.NeighborhoodReduce.time_reduce('120km', 'mean')
41.5±0.2ms 41.4±0.2ms 1.00 mpas_ocean.NeighborhoodReduce.time_reduce('120km', 'median')
156±6μs 159±7μs 1.02 mpas_ocean.NeighborhoodReduce.time_reduce('480km', 'mean')
455±20μs 476±7μs 1.05 mpas_ocean.NeighborhoodReduce.time_reduce('480km', 'median')
234k 234k 1.00 mpas_ocean.NeighborhoodReduce.track_peakmem_reduce('120km', 'mean')
235k 235k 1.00 mpas_ocean.NeighborhoodReduce.track_peakmem_reduce('120km', 'median')
19.5k 19.5k 1.00 mpas_ocean.NeighborhoodReduce.track_peakmem_reduce('480km', 'mean')
19.6k 19.6k 1.00 mpas_ocean.NeighborhoodReduce.track_peakmem_reduce('480km', 'median')
324±20μs 327±20μs 1.01 mpas_ocean.PointInPolygon.time_face_search_lonlat('120km')
317±20μs 325±10μs 1.03 mpas_ocean.PointInPolygon.time_face_search_lonlat('480km')
301±20μs 310±20μs 1.03 mpas_ocean.PointInPolygon.time_face_search_xyz('120km')
315±10μs 264±10μs ~0.84 mpas_ocean.PointInPolygon.time_face_search_xyz('480km')
96.2±0.4ms 97.1±0.6ms 1.01 mpas_ocean.RemapDownsample.time_bilinear_remapping
16.4±0.2ms 16.5±0.1ms 1.01 mpas_ocean.RemapDownsample.time_inverse_distance_weighted_remapping
15.0±0.1ms 15.0±0.2ms 1.00 mpas_ocean.RemapDownsample.time_nearest_neighbor_remapping
1.07±0.01s 1.08±0.01s 1.01 mpas_ocean.RemapUpsample.time_bilinear_remapping
25.1±0.9ms 25.0±0.4ms 1.00 mpas_ocean.RemapUpsample.time_inverse_distance_weighted_remapping
10.8±0.4ms 11.1±0.5ms 1.02 mpas_ocean.RemapUpsample.time_nearest_neighbor_remapping
7.44±0.06ms 7.31±0.07ms 0.98 mpas_ocean.ZonalAverage.time_zonal_average('120km')
4.15±0.06ms 4.17±0.05ms 1.01 mpas_ocean.ZonalAverage.time_zonal_average('480km')
1.0409346251991431 1.004232322227346 0.96 nogil_scaling.GILScaling.track_gil_scaling
945±7μs 964±6μs 1.02 open_dataset.OpenDataset.time_open_dataset('dataset', 'dataset')
1.77±0.01ms 1.78±0.02ms 1.00 open_dataset.OpenDataset.time_open_dataset('dataset', 'file')
3.76±0.02ms 3.74±0.02ms 0.99 open_dataset.OpenDataset.time_open_dataset('file', 'dataset')
4.46±0.01ms 4.46±0.03ms 1.00 open_dataset.OpenDataset.time_open_dataset('file', 'file')
152±3μs 152±1μs 1.00 open_dataset.OpenDataset.time_open_dataset('grid', 'dataset')
921±20μs 906±7μs 0.98 open_dataset.OpenDataset.time_open_dataset('grid', 'file')
1.83±0.01s 1.87±0.01s 1.02 plots.PlotContour.time_contour_projected
225±2ms 226±1ms 1.01 plots.PlotHealpix.time_default_plot(6)
2.08±0.01s 2.09±0.01s 1.00 plots.PlotHealpix.time_default_plot(8)
28M 28M 1.00 plots.PlotHealpix.track_peakmem_default_plot(6)
443M 443M 1.00 plots.PlotHealpix.track_peakmem_default_plot(8)
5.82±0.05ms 5.82±0.02ms 1.00 quad_hexagon.QuadHexagon.time_open_dataset
4.92±0.01ms 4.93±0.01ms 1.00 quad_hexagon.QuadHexagon.time_open_grid
408 408 1.00 quad_hexagon.QuadHexagon.track_nbytes_open_dataset
392 392 1.00 quad_hexagon.QuadHexagon.track_nbytes_open_grid
71.7k 71.7k 1.00 quad_hexagon.QuadHexagon.track_peakmem_open_dataset
71.5k 71.5k 1.00 quad_hexagon.QuadHexagon.track_peakmem_open_grid
10.2±0.2ms 10.1±0.3ms 0.99 subset.BoundingBox.time_bounding_box('120km')
5.96±0.03ms 5.85±0.1ms 0.98 subset.BoundingBox.time_bounding_box('480km')
2.38M 2.38M 1.00 subset.BoundingBox.track_peakmem_bounding_box('120km')
203k 203k 1.00 subset.BoundingBox.track_peakmem_bounding_box('480km')
2.85±6ms 2.70±0.2ms 0.95 subset.BoundingBoxHealpix.time_bounding_box(6)
14.9±0.6ms 11.3±0.2ms ~0.76 subset.BoundingBoxHealpix.time_bounding_box(8)
13.2M 13.1M 0.99 subset.BoundingBoxHealpix.track_peakmem_bounding_box(8)
770±5ms 763±4ms 0.99 to_raster.ToRaster.time_to_raster((10000.0, 10.0))
1.64±0.01s 1.63±0.01s 0.99 to_raster.ToRaster.time_to_raster((10000.0, 100.0))
1.91±0s 1.91±0.01s 1.00 to_raster.ToRaster.time_to_raster((100000.0, 100.0))
270M 270M 1.00 to_raster.ToRaster.track_peakmem((10000.0, 10.0))
680M 680M 1.00 to_raster.ToRaster.track_peakmem((10000.0, 100.0))
765M 765M 1.00 to_raster.ToRaster.track_peakmem((100000.0, 100.0))
99.8±2μs 99.5±1μs 1.00 to_xarray.UxDataArrayToXarray.time_to_xarray(10)
188±6μs 186±6μs 0.99 to_xarray.UxDatasetToXarray.time_to_xarray((100, 10))
1.78±0.05ms 1.71±0.01ms 0.96 to_xarray.UxDatasetToXarray.time_to_xarray((1000, 100))
428±7μs 423±10μs 0.99 to_xarray.UxDatasetToXarray.time_to_xarray_healpix((100, 10))
3.89±0.03ms 3.98±0.09ms 1.02 to_xarray.UxDatasetToXarray.time_to_xarray_healpix((1000, 100))

Benchmarks that have got worse:

Change Before [0e6c231] After [92a3f31] Ratio Benchmark (Parameter)
+ 305M 389M 1.28 face_bounds.FaceBoundsColdStartRss.track_peakmem_open_and_bounds(PosixPath('/home/runner/work/uxarray/uxarray/test/meshfiles/mpas/QU/oQU480.231010.nc'))
+ 306M 389M 1.27 face_bounds.FaceBoundsColdStartRss.track_peakmem_open_and_bounds(PosixPath('/home/runner/work/uxarray/uxarray/test/meshfiles/scrip/outCSne8/outCSne8.nc'))
+ 308M 389M 1.26 face_bounds.FaceBoundsColdStartRss.track_peakmem_open_and_bounds(PosixPath('/home/runner/work/uxarray/uxarray/test/meshfiles/ugrid/geoflow-small/grid.nc'))
+ 306M 389M 1.27 face_bounds.FaceBoundsColdStartRss.track_peakmem_open_and_bounds(PosixPath('/home/runner/work/uxarray/uxarray/test/meshfiles/ugrid/quad-hexagon/grid.nc'))
+ 284M 390M 1.37 import.Imports.track_peakmem_import_uxarray
+ 326M 388M 1.19 mpas_ocean.CrossSectionsPeakMem.track_peakmem_const_lat('120km', 1)
+ 326M 388M 1.19 mpas_ocean.CrossSectionsPeakMem.track_peakmem_const_lat('120km', 2)
+ 326M 388M 1.19 mpas_ocean.CrossSectionsPeakMem.track_peakmem_const_lat('120km', 4)
+ 308M 388M 1.26 mpas_ocean.CrossSectionsPeakMem.track_peakmem_const_lat('480km', 1)
+ 307M 388M 1.26 mpas_ocean.CrossSectionsPeakMem.track_peakmem_const_lat('480km', 2)
+ 307M 388M 1.26 mpas_ocean.CrossSectionsPeakMem.track_peakmem_const_lat('480km', 4)
+ 324M 389M 1.2 mpas_ocean.GradientColdStartRss.track_peakmem_gradient('120km')
+ 302M 389M 1.29 mpas_ocean.GradientColdStartRss.track_peakmem_gradient('480km')
+ 328M 389M 1.19 mpas_ocean.ZonalAveragePeakMem.track_peakmem_zonal_average('120km')
+ 309M 389M 1.26 mpas_ocean.ZonalAveragePeakMem.track_peakmem_zonal_average('480km')

@Sevans711
Sevans711 marked this pull request as ready for review December 1, 2026 22:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

run-benchmark Run ASV benchmark workflow scalability Related to scalability & performance efforts

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Avoid tiny numpy arrays in numba: optimize bounds.py

1 participant