Repository: UXARRAY/uxarray
Issue category: Performance Issue

Issue:
Slowdown in `__repr__` due to `n_nodes_per_face` construction triggering
When printing a `Grid`, there is an unnecessary trigger to the `n_nodes_per_face` variable, which has a noticeable impact on performance for larger grids. 


Hints:

Patch:
diff --git a/uxarray/formatting_html.py b/uxarray/formatting_html.py
index 8f15978b5..733232f5f 100644
--- a/uxarray/formatting_html.py
+++ b/uxarray/formatting_html.py
@@ -26,7 +26,7 @@ def _grid_sections(grid, max_items_collapse=15):
     spherical_coordinates = list(
         [coord for coord in ugrid.SPHERICAL_COORDS if coord in grid._ds]
     )
-    descritor = list(
+    descriptor = list(
         [desc for desc in descriptors.DESCRIPTOR_NAMES if desc in grid._ds]
     )
     connectivity = grid.connectivity
@@ -58,7 +58,7 @@ def _grid_sections(grid, max_items_collapse=15):
 
     sections.append(
         grid_descriptor_section(
-            grid._ds[descritor],
+            grid._ds[descriptor],
             max_items_collapse=max_items_collapse,
             name="Descriptors",
         )
diff --git a/uxarray/grid/grid.py b/uxarray/grid/grid.py
index 105841339..86a8006a7 100644
--- a/uxarray/grid/grid.py
+++ b/uxarray/grid/grid.py
@@ -650,36 +650,33 @@ def __repr__(self):
             if dim_name in self._ds.sizes:
                 dims_str += f"  * {dim_name}: {self._ds.sizes[dim_name]}\n"
 
-        dims_str += f"  * n_nodes_per_face: {self.n_nodes_per_face.shape}\n"
-
         coord_heading = "Grid Coordinates (Spherical):\n"
         coords_str = ""
-        for coord_name in ugrid.SPHERICAL_COORD_NAMES:
-            if coord_name in self._ds:
-                coords_str += f"  * {coord_name}: {getattr(self, coord_name).shape}\n"
+        for coord_name in list(
+            [coord for coord in ugrid.SPHERICAL_COORDS if coord in self._ds]
+        ):
+            coords_str += f"  * {coord_name}: {getattr(self, coord_name).shape}\n"
 
         coords_str += "Grid Coordinates (Cartesian):\n"
-        for coord_name in ugrid.CARTESIAN_COORD_NAMES:
-            if coord_name in self._ds:
-                coords_str += f"  * {coord_name}: {getattr(self, coord_name).shape}\n"
+        for coord_name in list(
+            [coord for coord in ugrid.CARTESIAN_COORDS if coord in self._ds]
+        ):
+            coords_str += f"  * {coord_name}: {getattr(self, coord_name).shape}\n"
 
         connectivity_heading = "Grid Connectivity Variables:\n"
         connectivity_str = ""
 
-        for conn_name in ugrid.CONNECTIVITY_NAMES:
-            if conn_name in self._ds:
-                connectivity_str += (
-                    f"  * {conn_name}: {getattr(self, conn_name).shape}\n"
-                )
+        for conn_name in self.connectivity:
+            connectivity_str += f"  * {conn_name}: {getattr(self, conn_name).shape}\n"
 
         descriptors_heading = "Grid Descriptor Variables:\n"
         descriptors_str = ""
-
-        for descriptor_name in descriptors.DESCRIPTOR_NAMES:
-            if descriptor_name in self._ds:
-                descriptors_str += (
-                    f"  * {descriptor_name}: {getattr(self, descriptor_name).shape}\n"
-                )
+        for descriptor_name in list(
+            [desc for desc in descriptors.DESCRIPTOR_NAMES if desc in self._ds]
+        ):
+            descriptors_str += (
+                f"  * {descriptor_name}: {getattr(self, descriptor_name).shape}\n"
+            )
 
         return (
             prefix
@@ -1134,7 +1131,7 @@ def face_node_connectivity(self) -> xr.DataArray:
         Nodes are in counter-clockwise order.
         """
 
-        if self._ds["face_node_connectivity"].values.ndim == 1:
+        if self._ds["face_node_connectivity"].ndim == 1:
             face_node_connectivity_1d = self._ds["face_node_connectivity"].values
             face_node_connectivity_2d = np.expand_dims(
                 face_node_connectivity_1d, axis=0


Test patch: