Skip to content

Avoid tiny numpy arrays in numba: optimize geometry.py - #1790

Draft
Sevans711 wants to merge 7 commits into
mainfrom
sevans/tinynumpynumba-optimize-geometry.py
Draft

Sevans711 wants to merge 7 commits into
mainfrom
sevans/tinynumpynumba-optimize-geometry.py

Conversation

@Sevans711

@Sevans711 Sevans711 commented Sep 25, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #XXX

Overview

Optimizes numba routines in uxarray/grid/geometry.py to avoid constructing many tiny numpy arrays inside numba routines, as discussed in #1648.

This one was much more complicated to make progress on, compared to the other sub-issues already solved under 1648. The main reasons are: (1) its methods assign numpy arrays whose sizes depend on input variables' shapes, instead of being constant, so it's not trivial to convert to tuples; (2) there is less documentation and more "dead" code here that isn't doing anything, so it took some extra time to figure out what is going on; (3) there are more connections with methods defined in other parts of the code, such as arcs.py, bounds.py, bilinear.py, utils.py, either calling methods from here or being called by methods from here, and (4) call sites are often very deep (>5 clicks before getting to a top-level user-facing function) so it's trickier to track and understand the intended and actual use-cases for these functions sometimes.

Originally attempted more optimizations than this but had to backtrack when it make pytest suite fail in nontrivial ways that were difficult to debug.

Still very much a draft PR, mostly curious to see if these changes are enough to make any dent in ASV benchmarks, or if it might be better to focus more on some of those other files (arcs.py, bounds.py, etc) first. I suspect there might not be huge improvements just yet, because there are still quite a few tiny numpy arrays, and elsewhere I only really saw large speedups after finishing the cleanup to avoid all relevant numpy allocations.

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 (_)
  • If touched any notebook files, cleared the output of all cells before committing
  • If added new notebook files, put into appropriate directories and referenced in appropriate files

AI Disclosure

AI Usage: Claude for discussion and some code suggestions, plus GitHub Copilot's inline code suggestions

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

and _check_intersection. Improves docstring, refactors slightly (but behavior should be the same) and removes the unused lonlat computations.

Doesn't avoid allocating the `intersection_points` buffer because it's nontrivial to avoid that. (I separately tried it but my changes led to pytest suite failing and I'm not really sure why...) That buffer is only used for faces crossing the equator anyways, so it probably isn't worthwhile to worry too much about optimizing it...
now it avoids allocating tiny numpy arrays.

(Nontrivial to optimize the call site (`barycentric_coordinates_cartesian`) though because the call site might return length 3 or length 4 numpy arrays, depending on inputs. Might be simple to optimize if forcing inputs to barycentric_coordinates_cartesian to be tuples, though, maybe?)
@Sevans711 Sevans711 added scalability Related to scalability & performance efforts run-benchmark Run ASV benchmark workflow labels Sep 25, 2026
@github-actions

github-actions Bot commented Sep 25, 2026 •

Copy link
Copy Markdown

ASV Benchmarking

Benchmark Comparison Results

Benchmarks that have improved:

Change Before [97f2f6f] <v2026.11.1> After [f2e3700] Ratio Benchmark (Parameter)
- 1.8M 1.61M 0.9 face_bounds.FaceBounds.track_peakmem_face_bounds(PosixPath('/home/runner/work/uxarray/uxarray/test/meshfiles/mpas/QU/oQU480.231010.nc'))
- 1.78M 1.59M 0.9 face_bounds.FaceBounds.track_peakmem_face_bounds(PosixPath('/home/runner/work/uxarray/uxarray/test/meshfiles/scrip/outCSne8/outCSne8.nc'))
- 1.94M 1.76M 0.91 face_bounds.FaceBounds.track_peakmem_face_bounds(PosixPath('/home/runner/work/uxarray/uxarray/test/meshfiles/ugrid/geoflow-small/grid.nc'))

Benchmarks that have stayed the same:

Change Before [97f2f6f] <v2026.11.1> After [f2e3700] Ratio Benchmark (Parameter)
1.23±0.02ms 1.23±0.03ms 1.00 connectivity.Connectivity.time_edge_face('120km')
456±10μs 444±10μs 0.97 connectivity.Connectivity.time_edge_face('480km')
3.02±0.03ms 3.01±0.1ms 1.00 connectivity.Connectivity.time_edge_node('120km')
1.08±0.03ms 1.08±0.02ms 1.00 connectivity.Connectivity.time_edge_node('480km')
61.1±3μs 59.4±3μs 0.97 connectivity.Connectivity.time_face_edge('120km')
58.7±2μs 58.7±2μs 1.00 connectivity.Connectivity.time_face_edge('480km')
785±20μs 787±30μs 1.00 connectivity.Connectivity.time_face_face('120km')
316±20μs 324±20μs 1.02 connectivity.Connectivity.time_face_face('480km')
58.1±2μs 57.6±7μs 0.99 connectivity.Connectivity.time_face_node('120km')
64.5±10μs 53.6±2μs ~0.83 connectivity.Connectivity.time_face_node('480km')
480±20μs 474±30μs 0.99 connectivity.Connectivity.time_n_nodes_per_face('120km')
365±20μs 378±20μs 1.03 connectivity.Connectivity.time_n_nodes_per_face('480km')
1.01±0.01ms 1.01±0.02ms 1.01 connectivity.Connectivity.time_node_edge('120km')
423±4μs 414±7μs 0.98 connectivity.Connectivity.time_node_edge('480km')
69.2±0.7ms 68.6±0.2ms 0.99 connectivity.Connectivity.time_node_face('120km')
4.48±0.04ms 4.48±0.1ms 1.00 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')
7.02±1ms 6.75±0.2ms 0.96 face_bounds.FaceBounds.time_face_bounds(PosixPath('/home/runner/work/uxarray/uxarray/test/meshfiles/mpas/QU/oQU480.231010.nc'))
2.37±0.05ms 2.33±0.1ms 0.98 face_bounds.FaceBounds.time_face_bounds(PosixPath('/home/runner/work/uxarray/uxarray/test/meshfiles/scrip/outCSne8/outCSne8.nc'))
8.03±0.2ms 7.07±8ms ~0.88 face_bounds.FaceBounds.time_face_bounds(PosixPath('/home/runner/work/uxarray/uxarray/test/meshfiles/ugrid/geoflow-small/grid.nc'))
1.50±0.04ms 1.49±0.03ms 0.99 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'))
896±10ns 867±20ns 0.97 geometry_kernels.AccucrossKernels.time_accucross
1.95±0.03μs 1.99±0.06μs 1.02 geometry_kernels.AccucrossKernels.time_accucross_pair
350±30ns 320±9ns 0.91 geometry_kernels.EFTPrimitives.time_acc_sqrt_re
330±30ns 320±10ns 0.97 geometry_kernels.EFTPrimitives.time_diff_of_products
275±20ns 281±10ns 1.02 geometry_kernels.EFTPrimitives.time_two_prod
290±20ns 376±100ns ~1.29 geometry_kernels.EFTPrimitives.time_two_sum
461±10ns 491±10ns 1.07 geometry_kernels.GCAConstLatIntersection.time_accux_constlat_kernel
510±9ns 506±5ns 0.99 geometry_kernels.GCAConstLatIntersection.time_gca_const_lat_intersection
566±20ns 561±10ns 0.99 geometry_kernels.GCAConstLatIntersection.time_try_gca_const_lat_intersection
716±30ns 747±30ns 1.04 geometry_kernels.GCAGCAIntersection.time_accux_gca_kernel
1.03±0.05μs 994±30ns 0.97 geometry_kernels.GCAGCAIntersection.time_gca_gca_intersection
1.16±0.04μs 1.08±0.03μs 0.94 geometry_kernels.GCAGCAIntersection.time_try_gca_gca_intersection
28.8±0.08μs 28.0±0.1μs 0.97 geometry_kernels.OrientPredicates.time_on_minor_arc
29.0±0.6μs 28.0±0.4μs 0.96 geometry_kernels.OrientPredicates.time_orient3d_on_sphere
4.49±0.4ms 3.64±0.3ms ~0.81 geometry_samebody.SameBodyConstLat.time_accux_dispatch
763±2μs 763±2μs 1.00 geometry_samebody.SameBodyConstLat.time_accux_kernel
3.95±0.2ms 3.75±0.2ms 0.95 geometry_samebody.SameBodyConstLat.time_fp64_dispatch
117±0.08μs 117±0.1μs 1.00 geometry_samebody.SameBodyConstLat.time_fp64_kernel
25.4±0.2ms 25.7±0.03ms 1.01 geometry_samebody_gcagca.SameBodyGcaGca.time_accux_dispatch
5.54±0ms 5.57±0.02ms 1.01 geometry_samebody_gcagca.SameBodyGcaGca.time_accux_kernel
19.7±0.09ms 20.4±0.1ms 1.04 geometry_samebody_gcagca.SameBodyGcaGca.time_fp64_dispatch
703±3μs 697±4μs 0.99 geometry_samebody_gcagca.SameBodyGcaGca.time_fp64_kernel
981±9ms 965±10ms 0.98 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
104±2ms 103±0.6ms 0.99 lazy_grid_construction.OpenGridChunked.time_open_grid('120km')
125±2ms 125±2ms 1.01 lazy_grid_construction.OpenGridChunked.time_open_grid('480km')
3.43M 3.23M 0.94 lazy_grid_construction.OpenGridChunked.track_peakmem_open_grid('120km')
2.41M 2.42M 1.00 lazy_grid_construction.OpenGridChunked.track_peakmem_open_grid('480km')
2.01±0.06ms 1.92±0.06ms 0.96 mpas_ocean.AzimuthalAverage.time_azimuthal_average('120km')
743±6μs 732±7μs 0.99 mpas_ocean.AzimuthalAverage.time_azimuthal_average('480km')
2.49±0.08ms 2.50±0.02ms 1.00 mpas_ocean.CheckNorm.time_check_norm('120km')
1.94±0.09ms 1.98±0.02ms 1.02 mpas_ocean.CheckNorm.time_check_norm('480km')
832±10μs 827±9μs 0.99 mpas_ocean.ConnectivityConstruction.time_face_face_connectivity('120km')
374±6μs 384±6μs 1.03 mpas_ocean.ConnectivityConstruction.time_face_face_connectivity('480km')
557±20μs 566±20μs 1.02 mpas_ocean.ConnectivityConstruction.time_n_nodes_per_face('120km')
458±50μs 403±2μs ~0.88 mpas_ocean.ConnectivityConstruction.time_n_nodes_per_face('480km')
5.16±0.02ms 5.16±0.06ms 1.00 mpas_ocean.ConstructFaceLatLon.time_cartesian_averaging('120km')
3.73±0.1ms 3.67±0.03ms 0.98 mpas_ocean.ConstructFaceLatLon.time_cartesian_averaging('480km')
102±0.5ms 105±1ms 1.03 mpas_ocean.ConstructFaceLatLon.time_welzl('120km')
9.53±0.1ms 9.80±0.1ms 1.03 mpas_ocean.ConstructFaceLatLon.time_welzl('480km')
15.6±0.1ms 15.5±0.05ms 0.99 mpas_ocean.ConstructTreeStructures.time_ball_tree('120km')
758±10μs 774±40μs 1.02 mpas_ocean.ConstructTreeStructures.time_ball_tree('480km')
7.92±0.09ms 7.85±0.02ms 0.99 mpas_ocean.ConstructTreeStructures.time_kd_tree('120km')
437±20μs 458±20μs 1.05 mpas_ocean.ConstructTreeStructures.time_kd_tree('480km')
549±10ms 534±3ms 0.97 mpas_ocean.CrossSections.time_const_lat('120km', 1)
271±2ms 273±4ms 1.01 mpas_ocean.CrossSections.time_const_lat('120km', 2)
138±0.6ms 139±1ms 1.00 mpas_ocean.CrossSections.time_const_lat('120km', 4)
491±6ms 483±0.8ms 0.98 mpas_ocean.CrossSections.time_const_lat('480km', 1)
240±1ms 247±5ms 1.03 mpas_ocean.CrossSections.time_const_lat('480km', 2)
124±1ms 125±1ms 1.01 mpas_ocean.CrossSections.time_const_lat('480km', 4)
19.3±0.1ms 19.2±0.09ms 0.99 mpas_ocean.DualMesh.time_dual_mesh_construction('120km')
2.34±0.02ms 2.31±0.02ms 0.99 mpas_ocean.DualMesh.time_dual_mesh_construction('480km')
8.52±0.07ms 8.69±0.2ms 1.02 mpas_ocean.FaceAreas.time_face_areas('120km')
2.49±0.07ms 2.56±0.1ms 1.03 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')
687k 687k 1.00 mpas_ocean.FaceAreas.track_peakmem_face_areas('480km')
53.3±0.9ms 55.1±1ms 1.03 mpas_ocean.GeoDataFrame.time_to_geodataframe('120km', 'exclude')
155±2ms 159±1ms 1.02 mpas_ocean.GeoDataFrame.time_to_geodataframe('120km', 'split')
4.93±0.2ms 5.07±0.3ms 1.03 mpas_ocean.GeoDataFrame.time_to_geodataframe('480km', 'exclude')
30.6±0.7ms 31.6±0.2ms 1.03 mpas_ocean.GeoDataFrame.time_to_geodataframe('480km', 'split')
11.4±0.3ms 11.1±0.2ms 0.97 mpas_ocean.Gradient.time_gradient('120km')
1.72±0.01ms 1.75±0.01ms 1.02 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')
265±20μs 277±10μs 1.05 mpas_ocean.HoleEdgeIndices.time_construct_hole_edge_indices('120km')
104±1μs 108±5μs 1.04 mpas_ocean.HoleEdgeIndices.time_construct_hole_edge_indices('480km')
171±1μs 173±10μs 1.01 mpas_ocean.Integrate.time_integrate('120km')
151±1μs 150±1μs 0.99 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')
108±0.5ms 107±0.6ms 0.99 mpas_ocean.MatplotlibConversion.time_dataarray_to_polycollection('120km', 'exclude')
108±1ms 107±0.6ms 1.00 mpas_ocean.MatplotlibConversion.time_dataarray_to_polycollection('120km', 'include')
108±1ms 106±0.8ms 0.98 mpas_ocean.MatplotlibConversion.time_dataarray_to_polycollection('120km', 'split')
7.66±0.02ms 7.34±0.06ms 0.96 mpas_ocean.MatplotlibConversion.time_dataarray_to_polycollection('480km', 'exclude')
7.63±0.1ms 7.44±0.2ms 0.98 mpas_ocean.MatplotlibConversion.time_dataarray_to_polycollection('480km', 'include')
7.68±0.09ms 7.45±0.03ms 0.97 mpas_ocean.MatplotlibConversion.time_dataarray_to_polycollection('480km', 'split')
234±0.5ms 236±1ms 1.01 mpas_ocean.NeighborhoodBuild.time_build('120km', 1.0)
488±4ms 487±3ms 1.00 mpas_ocean.NeighborhoodBuild.time_build('120km', 5.0)
12.6±0.04ms 12.8±0.1ms 1.01 mpas_ocean.NeighborhoodBuild.time_build('480km', 1.0)
15.8±0.2ms 15.8±0.7ms 1.00 mpas_ocean.NeighborhoodBuild.time_build('480km', 5.0)
231±2ms 234±1ms 1.01 mpas_ocean.NeighborhoodBuild.time_query_radius('120km', 1.0)
483±2ms 483±3ms 1.00 mpas_ocean.NeighborhoodBuild.time_query_radius('120km', 5.0)
12.4±0.03ms 12.4±0.05ms 0.99 mpas_ocean.NeighborhoodBuild.time_query_radius('480km', 1.0)
15.7±0.1ms 15.5±0.07ms 0.99 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)
32.4±0.8ms 32.4±0.3ms 1.00 mpas_ocean.NeighborhoodDask.time_mean('120km', 'grid_chunks')
14.6±0.7ms 14.5±0.07ms 0.99 mpas_ocean.NeighborhoodDask.time_mean('120km', 'numpy')
30.2±0.7ms 30.1±1ms 1.00 mpas_ocean.NeighborhoodDask.time_mean('120km', 'time_chunks')
7.32±0.1ms 7.31±0.03ms 1.00 mpas_ocean.NeighborhoodDask.time_mean('480km', 'grid_chunks')
508±90μs 406±4μs ~0.80 mpas_ocean.NeighborhoodDask.time_mean('480km', 'numpy')
5.12±0.06ms 5.02±0.03ms 0.98 mpas_ocean.NeighborhoodDask.time_mean('480km', 'time_chunks')
5.74M 5.82M 1.01 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')
755k 688k 0.91 mpas_ocean.NeighborhoodDask.track_peakmem_mean('480km', 'grid_chunks')
177k 177k 1.00 mpas_ocean.NeighborhoodDask.track_peakmem_mean('480km', 'numpy')
533k 534k 1.00 mpas_ocean.NeighborhoodDask.track_peakmem_mean('480km', 'time_chunks')
4.33±0.01s 4.36±0.01s 1.01 mpas_ocean.NeighborhoodReduce.time_dataset_reduce('120km', 'mean')
4.47±0.01s 4.49±0.01s 1.00 mpas_ocean.NeighborhoodReduce.time_dataset_reduce('120km', 'median')
116±0.4ms 116±0.4ms 0.99 mpas_ocean.NeighborhoodReduce.time_dataset_reduce('480km', 'mean')
117±0.6ms 118±0.8ms 1.01 mpas_ocean.NeighborhoodReduce.time_dataset_reduce('480km', 'median')
490±1ms 492±2ms 1.00 mpas_ocean.NeighborhoodReduce.time_neighborhood_reduce('120km', 'mean')
526±2ms 526±4ms 1.00 mpas_ocean.NeighborhoodReduce.time_neighborhood_reduce('120km', 'median')
16.2±0.1ms 16.1±0.1ms 0.99 mpas_ocean.NeighborhoodReduce.time_neighborhood_reduce('480km', 'mean')
16.2±0.03ms 16.4±0.1ms 1.01 mpas_ocean.NeighborhoodReduce.time_neighborhood_reduce('480km', 'median')
4.48±0.02ms 4.53±0.06ms 1.01 mpas_ocean.NeighborhoodReduce.time_reduce('120km', 'mean')
37.0±0.2ms 37.4±0.2ms 1.01 mpas_ocean.NeighborhoodReduce.time_reduce('120km', 'median')
192±2μs 205±8μs 1.07 mpas_ocean.NeighborhoodReduce.time_reduce('480km', 'mean')
471±10μs 461±6μs 0.98 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')
344±20μs 383±8μs ~1.11 mpas_ocean.PointInPolygon.time_face_search_lonlat('120km')
324±30μs 309±10μs 0.95 mpas_ocean.PointInPolygon.time_face_search_lonlat('480km')
343±20μs 342±10μs 1.00 mpas_ocean.PointInPolygon.time_face_search_xyz('120km')
279±20μs 339±10μs ~1.21 mpas_ocean.PointInPolygon.time_face_search_xyz('480km')
97.5±1ms 100±1ms 1.03 mpas_ocean.RemapDownsample.time_bilinear_remapping
16.5±0.3ms 17.0±0.2ms 1.03 mpas_ocean.RemapDownsample.time_inverse_distance_weighted_remapping
15.1±0.4ms 15.4±0.3ms 1.02 mpas_ocean.RemapDownsample.time_nearest_neighbor_remapping
780±6ms 776±2ms 0.99 mpas_ocean.RemapUpsample.time_bilinear_remapping
23.0±0.2ms 23.3±0.2ms 1.01 mpas_ocean.RemapUpsample.time_inverse_distance_weighted_remapping
10.1±0.2ms 10.0±0.02ms 0.99 mpas_ocean.RemapUpsample.time_nearest_neighbor_remapping
7.82±0.3ms 7.67±0.1ms 0.98 mpas_ocean.ZonalAverage.time_zonal_average('120km')
4.66±0.07ms 4.55±0.08ms 0.98 mpas_ocean.ZonalAverage.time_zonal_average('480km')
1.0426559830163067 1.0427454074477283 1.00 nogil_scaling.GILScaling.track_gil_scaling
956±30μs 963±10μs 1.01 open_dataset.OpenDataset.time_open_dataset('dataset', 'dataset')
1.76±0.08ms 1.72±0.01ms 0.98 open_dataset.OpenDataset.time_open_dataset('dataset', 'file')
3.79±0.04ms 3.79±0.05ms 1.00 open_dataset.OpenDataset.time_open_dataset('file', 'dataset')
4.49±0.05ms 4.50±0.03ms 1.00 open_dataset.OpenDataset.time_open_dataset('file', 'file')
146±2μs 149±10μs 1.02 open_dataset.OpenDataset.time_open_dataset('grid', 'dataset')
885±10μs 873±10μs 0.99 open_dataset.OpenDataset.time_open_dataset('grid', 'file')
1.96±0.02s 1.98±0.03s 1.01 plots.PlotContour.time_contour_projected
226±3ms 226±1ms 1.00 plots.PlotHealpix.time_default_plot(6)
2.06±0.01s 2.06±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.93±0.01ms 6.12±0.02ms 1.03 quad_hexagon.QuadHexagon.time_open_dataset
5.22±0.03ms 5.07±0.04ms 0.97 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
9.48±0.2ms 9.28±0.2ms 0.98 subset.BoundingBox.time_bounding_box('120km')
4.96±0.08ms 4.87±0.05ms 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')
3.27±8ms 3.04±8ms 0.93 subset.BoundingBoxHealpix.time_bounding_box(6)
12.9±0.3ms 12.4±0.08ms 0.96 subset.BoundingBoxHealpix.time_bounding_box(8)
2.3M 2.1M 0.91 subset.BoundingBoxHealpix.track_peakmem_bounding_box(6)
13.2M 13.2M 1.00 subset.BoundingBoxHealpix.track_peakmem_bounding_box(8)
739±5ms 734±5ms 0.99 to_raster.ToRaster.time_to_raster((10000.0, 10.0))
1.55±0.01s 1.53±0.01s 0.99 to_raster.ToRaster.time_to_raster((10000.0, 100.0))
1.80±0.02s 1.79±0.02s 0.99 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))
88.5±1μs 87.4±0.5μs 0.99 to_xarray.UxDataArrayToXarray.time_to_xarray(10)
238±3μs 230±5μs 0.97 to_xarray.UxDatasetToXarray.time_to_xarray((100, 10))
2.24±0.06ms 2.21±0.03ms 0.99 to_xarray.UxDatasetToXarray.time_to_xarray((1000, 100))
511±6μs 497±3μs 0.97 to_xarray.UxDatasetToXarray.time_to_xarray_healpix((100, 10))
4.75±0.03ms 4.73±0.1ms 1.00 to_xarray.UxDatasetToXarray.time_to_xarray_healpix((1000, 100))

Benchmarks that have got worse:

Change Before [97f2f6f] <v2026.11.1> After [f2e3700] Ratio Benchmark (Parameter)
+ 305M 388M 1.27 face_bounds.FaceBoundsColdStartRss.track_peakmem_open_and_bounds(PosixPath('/home/runner/work/uxarray/uxarray/test/meshfiles/mpas/QU/oQU480.231010.nc'))
+ 306M 388M 1.27 face_bounds.FaceBoundsColdStartRss.track_peakmem_open_and_bounds(PosixPath('/home/runner/work/uxarray/uxarray/test/meshfiles/scrip/outCSne8/outCSne8.nc'))
+ 308M 388M 1.26 face_bounds.FaceBoundsColdStartRss.track_peakmem_open_and_bounds(PosixPath('/home/runner/work/uxarray/uxarray/test/meshfiles/ugrid/geoflow-small/grid.nc'))
+ 306M 388M 1.27 face_bounds.FaceBoundsColdStartRss.track_peakmem_open_and_bounds(PosixPath('/home/runner/work/uxarray/uxarray/test/meshfiles/ugrid/quad-hexagon/grid.nc'))
+ 280M 389M 1.39 import.Imports.track_peakmem_import_uxarray
+ 327M 390M 1.19 mpas_ocean.CrossSectionsPeakMem.track_peakmem_const_lat('120km', 1)
+ 327M 390M 1.19 mpas_ocean.CrossSectionsPeakMem.track_peakmem_const_lat('120km', 2)
+ 327M 390M 1.19 mpas_ocean.CrossSectionsPeakMem.track_peakmem_const_lat('120km', 4)
+ 309M 390M 1.26 mpas_ocean.CrossSectionsPeakMem.track_peakmem_const_lat('480km', 1)
+ 309M 390M 1.26 mpas_ocean.CrossSectionsPeakMem.track_peakmem_const_lat('480km', 2)
+ 309M 390M 1.26 mpas_ocean.CrossSectionsPeakMem.track_peakmem_const_lat('480km', 4)
+ 324M 388M 1.2 mpas_ocean.GradientColdStartRss.track_peakmem_gradient('120km')
+ 301M 388M 1.29 mpas_ocean.GradientColdStartRss.track_peakmem_gradient('480km')
+ 328M 388M 1.18 mpas_ocean.ZonalAveragePeakMem.track_peakmem_zonal_average('120km')
+ 309M 388M 1.26 mpas_ocean.ZonalAveragePeakMem.track_peakmem_zonal_average('480km')

@cmdupuis3

Copy link
Copy Markdown
Collaborator

Seems like this might be a sub-issue of #1789 2b?

@Sevans711

Copy link
Copy Markdown
Collaborator Author

Seems like this might be a sub-issue of #1789 2b?

Agreed, thank you for flagging this connection. I think #1789 2b is basically the same thing as implied by #1648 (though 1789 additionally does a good job of clearly pointing out many locations where this optimization could still help). My preference would be to continue tracking that via 1648 if that sounds reasonable?

This PR fixes some of the geometry.py topics pointed out in that table, but it isn't yet seeing any noticeable speedups, so my plan is to keep it as draft for now, revisit after some of the other topics there get fixed, and then make a corresponding sub-issue of 1648 once this is ready for review.

@cmdupuis3

cmdupuis3 commented Sep 29, 2026 •

Copy link
Copy Markdown
Collaborator

Yeah, that's fine, I'll just add a note in #1789 to track the sub-issues over there. I think the work can happen in parallel to the other sections, so that's actually kind of nice.

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.

2 participants