-
Type:
Bug
-
Resolution: Fixed
-
Priority:
Unknown
-
Affects Version/s: None
-
Component/s: Performance
-
None
-
None
-
Fully Compatible
-
Ruby Drivers
-
Not Needed
-
-
None
-
None
-
None
-
None
-
None
-
None
Mongoid resolves a field's stored name on every attribute read via `Mongoid::Fields.database_field_name`. For a key with no ".", it still runs `key.split('.', 2)` and dups the alias, allocating on a very hot path. Allocation profiling of a load-and-read cycle showed this method as the top source of new objects (~80% of allocations were Mongoid field handling, bson <1%).
This is the same issue fixed for the matcher in PR #5868; `database_field_name` has the identical pattern and was not covered.
Fix: short-circuit the no-"." case — return `aliased_fields[key] || key`. Measured ~11% fewer allocations per document.
Benchmarked with https://gist.github.com/phedinkus/3a945c05818c88fc9b816124d01d3a64
- related to
-
MONGOID-5805 Performance degradation when upgrading from Mongoid 7.1.11
-
- Closed
-