Merge pull request #12037 from SamSaffron/mem_alloc

Performance: Reduce memory allocations in Active Record