Version 10.71.0 speeds up the ORM Via Segregated Accessors and Mutators
This version extends the high-performance "segregated closures" architecture from model relationships to Eloquent accessors and mutators. By moving attribute mutation away from dynamic method dispatch and expensive string manipulations (Str::studly), this significantly reduces CPU and memory overhead during both direct property access and array/JSON serialization.
Key Changes
- Segregated Definition Maps: Introduces segregatedAccessorsMap() and segregatedMutatorsMap() to allow developers to define accessors and mutators explicitly using closures.
- Static Global Caching: Adds $segregatedAccessorsGlobalMap and $segregatedMutatorsGlobalMap to cache closures statically across all instances of a model.
- Strict "Miss" Caching: The static maps now explicitly cache false when an attribute does not have a mutator. This completely eliminates repeated reflection and string-manipulation overhead for standard database columns, achieving true O(1) lookups for both hits and misses.
- Hot-Path Optimization: Rewires core HasAttributes execution paths (hasGetMutator, mutateAttribute, hasSetMutator, and setMutatedAttributeValue) to resolve through the new segregated map lookup, completely bypassing reflection and string parsing on the hot path.
- Auto-Promotion (100% BC): Legacy get...Attribute and set...Attribute methods are lazily auto-promoted into the segregated caches using first-class callable syntax. They benefit from the same speed improvements without requiring developers to rewrite existing code.
- Serialization Integrity: Updates cacheMutatedAttributes to automatically discover keys from the segregated maps, normalize them respecting static::$snakeAttributes, and safely merge them into the existing $mutatorCache so they appear correctly in $model->toArray() and JSON responses.
Impact:
- Performance: Massive reduction in CPU cycles, string manipulations, and dynamic method calls when hydrating, setting, or serializing model collections.
- Backward Compatibility: 100% backward compatible. Existing string-based mutators and modern Attribute return-type mutators will continue to function exactly as before alongside the new logic.
