Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reduce allocations in BelongsToAssociation#replace_keys
Using the same benchmark as in #51726 `replace_keys` always allocate a multiple arrays to support composite primary keys, even though most primary keys likely aren't composite. And even when they are, we can avoid needless allocations by not using `Array#zip`. This reduce allocations by 18% (8k) on that benchmark. Before: ``` Total allocated: 4.88 MB (44495 objects) Total retained: 4.16 MB (32043 objects) allocated memory by file ----------------------------------- ... 320.00 kB activerecord/lib/active_record/associations/belongs_to_association.rb allocated objects by file ----------------------------------- ... 8000 activerecord/lib/active_record/associations/belongs_to_association.rb ``` After: ``` Total allocated: 4.56 MB (36495 objects) Total retained: 4.16 MB (32041 objects) ``` NB: `belongs_to_association` doesn't show up in top files anymore
- Loading branch information