Merge pull request #5486 from kumpera/fix_array_dispatch_perf