[Roll forward -- Take 2] Optimize large JAX Mesh construction #40785

Merged
copybara-service[bot] opened 3:16am on September 18, 2026 wanted to merge 1 commit into google/jax main from
test_983759493
copybara-service[bot]
Diff Delta:
0
About 0 Diff Delta/hour
Classified as:  General

copybara-service[bot]'s Description of Work

[Roll forward -- Take 2] Optimize large JAX Mesh construction


  • Avoid intermediate tuple -> np.ndarray reallocation: Previously Mesh._create took flat_devices_tuple and reallocated an np.ndarray via np.array(flat_devices_tuple).reshape(device_shape). We now introduce _HashableDeviceArray wrapping the original np.ndarray and xc.DeviceList, avoiding the array reallocation.

  • Reuse xc.DeviceList: Cache _cached_device_list on the Mesh instance during construction and return it directly from the _internal_device_list property, avoiding redundant DeviceList allocations.

Reverts 008c954b905e7119157f55dc6ea7d16ee15ce05f

1 total changed file
Loading changes...
Review complete ๐Ÿ’ช
Thus concludes todayโ€™s episode of โ€œJust One Small Changeโ€