PERF: performance regression in frame/apply (GH5654)

closes #5654