Skip to content

[13.x] prefer isset() over in_array() for better performance - #59457

Merged
taylorotwell merged 1 commit into
laravel:13.xfrom
browner12:AB-in-array-to-isset
Mar 30, 2026
Merged

taylorotwell merged 1 commit into
laravel:13.xfrom
browner12:AB-in-array-to-isset

Conversation

@browner12

Copy link
Copy Markdown
Contributor

the class_uses_recursive() method returns an array where both the key and value are the same fully qualified class name. by switching to isset() we get O(1) performance, while in_array() gives O(n) performance.

  • also remove some single use temporary variables
  • passes multiple arguments to isset() rather than multiple separate calls

the `class_uses_recursive()` method returns an array where both the key and value are the same fully qualified class name. by switching to `isset()` we get O(1) performance, while `in_array()` gives O(n) performance.

- also remove some single use temporary variables
- passes multiple arguments to `isset()` rather than multiple separate calls
@taylorotwell
taylorotwell merged commit c2509e3 into laravel:13.x Mar 30, 2026
54 checks passed
@browner12
browner12 deleted the AB-in-array-to-isset branch March 31, 2026 01:49
jonagoldman pushed a commit to deplox/laravel-framework that referenced this pull request Apr 30, 2026
)

the `class_uses_recursive()` method returns an array where both the key and value are the same fully qualified class name. by switching to `isset()` we get O(1) performance, while `in_array()` gives O(n) performance.

- also remove some single use temporary variables
- passes multiple arguments to `isset()` rather than multiple separate calls
binaryfire added a commit to hypervel/components-backup that referenced this pull request Oct 1, 2026
Port refreshForUpdate with the shared refresh query path, upstream unit and integration coverage, and usage documentation. Preserve model key validation and relationship reload behavior.

Make relationship touching honor WithoutTimestamps and the same property/attribute precedence as model initialization. Disabled models could otherwise write updated_at, including on tables without that column. Strengthen the precedence cases and reconcile both attribute cache-order tests against the existing instance-based cache.

Complete the missing multi-attribute touch model test and documentation. Use the upstream keyed AsPivot lookup in the moved refresh helper; the rest of the trait lookup PR remains under reconciliation.

Upstream: laravel/framework at 01d008c9b5f32cb7c5e50a9a22273113d810b2a2.

laravel/framework#61247
laravel/framework#59175
laravel/framework#61073
laravel/framework#60815
laravel/framework#59457

Validation: timestamp precedence regressions failed before the correction and pass afterward; SQLite relation touching verifies inherited disabling. Changed test files, affected Eloquent ParaTest, full source/type analysis, and scoped formatting pass. Refresh integration tests also pass after the final trait lookup correction.
binaryfire added a commit to hypervel/components-backup that referenced this pull request Oct 1, 2026
Port the remaining changes from Laravel #59457 using the current 13.x source at 01d008c9b5f32cb7c5e50a9a22273113d810b2a2. Recursive trait discovery returns trait names as both keys and values, so these checks can use direct key lookups instead of scanning the values.

Update generators, model capabilities, pivot detection, ULID foreign keys, seeders and queued handlers. Combine the batch trait checks and remove the unnecessary Seeder array_flip. Preserve existing model caches and coroutine-safe cloning of mapped handlers and listeners. The other upstream sites already use keyed lookups, including refresh completed in the preceding commit.

Validation: affected database, console and event suites, queue handler unit and integration tests, model pruning integration tests, scoped formatting and full source/type analysis pass.

laravel/framework#59457
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants