PERF: cache sortings in groupby.ops
xref #51077 doesn't close as there is more we can potentially cache.

Also moved apply_groupwise down to be adjacent to thematically similar methods, unrelated.


Thanks @jbrockmendel 