PERF: Try fast/slow paths only once in DataFrameGroupby.transform
- [x] closes #41598
- [x] Ensure all linting tests pass, see [here](https://pandas.pydata.org/pandas-docs/dev/development/contributing.html#code-standards) for how to run them
- [x] whatsnew entry

Still need to run ASVs to measure performance, making sure CI passes first.

Edit: ASV results for 7b86fdb

```
       before           after         ratio
     [9f6a91ae]       [7b86fdb9]
     <groupby_transform_path~1>       <groupby_transform_path>
-     23.8±0.07ms         21.4±2ms     0.90  groupby.Nth.time_series_nth_all('float32')
-      11.8±0.1ms       10.4±0.6ms     0.88  groupby.Nth.time_frame_nth('object')
-      27.1±0.1ms       23.3±0.1ms     0.86  groupby.Nth.time_series_nth_all('object')
-      19.4±0.2ms       16.5±0.2ms     0.85  groupby.Nth.time_groupby_nth_all('float64')
-      21.7±0.2ms       18.4±0.3ms     0.85  groupby.Nth.time_frame_nth_any('float32')
-      24.1±0.1ms       20.2±0.2ms     0.84  groupby.Nth.time_series_nth_any('float64')
-      24.0±0.2ms      20.1±0.05ms     0.84  groupby.Nth.time_series_nth_all('float64')
-      56.4±0.4ms       20.1±0.4ms     0.36  groupby.TransformEngine.time_dataframe_cython(False)
-      56.5±0.4ms       20.1±0.4ms     0.36  groupby.TransformEngine.time_dataframe_cython(True)

SOME BENCHMARKS HAVE CHANGED SIGNIFICANTLY.
PERFORMANCE INCREASED.
```