You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Reduce allocations in BelongsToAssociation#replace_keys
Using the same benchmark as in rails#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
0 commit comments