Skip to content

Optimize prepare_inherited_attributes() and support helpers - #20350

Open
hamdyelbatal122 wants to merge 1 commit into
filamentphp:5.xfrom
hamdyelbatal122:perf/prepare-inherited-attributes-optimization
Open

Optimize prepare_inherited_attributes() and support helpers#20350
hamdyelbatal122 wants to merge 1 commit into
filamentphp:5.xfrom
hamdyelbatal122:perf/prepare-inherited-attributes-optimization

Conversation

@hamdyelbatal122

@hamdyelbatal122 hamdyelbatal122 commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Description

This PR optimizes prepare_inherited_attributes() and support helpers (locale_has_pluralization(), get_model_label(), is_app_url()) by removing unnecessary Collection and Stringable object allocations in favor of native PHP iteration and memoization.

Changes

  • Refactored prepare_inherited_attributes() from a collect() / str() pipeline to a single-pass foreach loop with str_starts_with().
  • Added string typecasting to attribute keys for safe numeric key handling.
  • Added static memoization for locale_has_pluralization() and get_model_label().
  • Replaced str()->startsWith() with str_starts_with() in is_app_url().

Benchmark (100k iterations of prepare_inherited_attributes())

  • Before: ~367ms
  • After: ~62ms (~6x speedup, 83% time reduction, 0 extra object allocations)

Testing

Ran full test suite (707 passed in Support, all playground tests passing).

@hamdyelbatal122 hamdyelbatal122 changed the title perf(support): optimize prepare_inherited_attributes() and helper functions Optimize prepare_inherited_attributes() and support helpers Aug 8, 2026
@hamdyelbatal122
hamdyelbatal122 force-pushed the perf/prepare-inherited-attributes-optimization branch from 00a68a1 to 5d6647b Compare August 8, 2026 07:41
@danharrin danharrin added this to the v4 milestone Aug 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants