Skip to content

[4.x] Prefer new Collection() over collect() helper - #10505

Open
ghabriel25 wants to merge 1 commit into
livewire:4.xfrom
ghabriel25:refactor/collect-to-new-collection
Open

[4.x] Prefer new Collection() over collect() helper#10505
ghabriel25 wants to merge 1 commit into
livewire:4.xfrom
ghabriel25:refactor/collect-to-new-collection

Conversation

@ghabriel25

Copy link
Copy Markdown
Contributor

Summary

This PR is a pure refactor that replaces calls to Laravel’s global collect() helper with direct instantiation of new Collection(...) throughout the Livewire 4.x codebase.

It aligns Livewire with a convention adopted in the Laravel framework itself, which prefers new Collection() for:

  • Slightly better performance (one fewer function call)
  • A shorter call stack
  • Makes DX slightly better when navigating the framework
  • Consistency across the framework internals

The change has no intended behavioral impact. All existing Collection method chaining, filtering, mapping, etc. continue to work exactly as before.

Motivation

The collect() helper is a thin convenience wrapper without any logic in it. Calling the helper adds an unnecessary extra stack frame and a global function lookup.

Laravel core has begun preferring the explicit constructor in its own source for the reasons listed above. This PR brings Livewire in line with that style.

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.

1 participant