text: Title: regression in graph construction time for `Array.ravel()`
  Body: **Minimal Complete Verifiable Example**:
  
  ```python
  import dask.array
  import numpy as np
  
  shape=(28, 30, 8, 1, 21, 3)
  dtype=np.int64
  chunksize=(1, 1, 1, 1, 1, 3)
  
  array = dask.array.from_array(np.arange(np.prod(shape)).reshape(shape), chunks=chunksize)
  %timeit array.ravel()
  ```
  
  This times at 60ms on 2024.6.0, and 275ms on 2024.12.0
  
  Snakeviz blames `_task_spec.py`
  
  <img width="776" alt="image" src="https://github.com/user-attachments/assets/3b231308-dbcc-4314-addc-487715c28826">
  
  
  
  
  **Environment**:
  
  - Dask version: 2024.12.0
  - Python version: 3.12
  - Operating System: macos
  - Install method (conda, pip, source): pip
  