Skip to content

Conversation

@jmarble
Copy link

@jmarble jmarble commented Oct 24, 2025

Adds duplicateStrings() method to Collection and LazyCollection for optimized string duplicate detection.

Companion to uniqueStrings() (#57517) - not a duplicate PR, LOL!

Provides 8-40x performance improvement over duplicates() using isset() hash lookups.
Supports keys, closures, and nested properties.

collect(['a', 'b', 'a', 'c'])->duplicateStrings(); // ['a']
collect($users)->duplicateStrings('email');
collect($products)->duplicateStrings(fn($p) => strtolower($p->sku));

Completes the string-optimized API for symmetry:

  • unique() / duplicates()
  • uniqueStrings() / duplicateStrings()

Adds optimized string duplicate detection as a companion to uniqueStrings().
Uses isset() hash lookups for O(n) performance (8-40x faster than duplicates()
for string-based operations).

Supports keys, closures, and nested property access.
@jmarble jmarble force-pushed the feature/collection-duplicate-strings branch from b82cb3e to a04d24c Compare October 24, 2025 03:28
@taylorotwell
Copy link
Member

I just am not confident this is a real-world bottleneck for applications that requires a new method.

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