Conversation
Reduce per-field/per-attribute work on the form rendering path: - AttributeBuilder: replace the 168-element array rebuilt on every attribute with a keyed const map, swapping the O(n) in_array scan for an O(1) isset lookup. Use native str_starts_with instead of Str::of()->startsWith (no Stringable allocation per attribute) and array_unique/implode instead of a Collection. validHtmlAttributes() is kept for backward compatibility, now derived from the const. - FormAssets: cache the core.js read in a static property so it is read from disk once per request instead of on every compileScripts(). - FormMaker: cache the raw default.js/validation.js reads via a static cache; per-call config replacements are unchanged so output is identical. All output-preserving internal refactors. No public API change. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Performance optimizations on the hot per-field / per-attribute form rendering path. All changes are output-preserving internal refactors — no public API change and no behavior change.
1.
AttributeBuilder(the main win)private const VALID_HTML_ATTRIBUTESkeyed map, swapping the O(n)in_array()scan for an O(1)isset()lookup.Str::of($key)->startsWith(...)with nativestr_starts_with()(noStringableallocation per attribute) and removed the now-unusedStrimport.collect($html)->unique()->implode(' ')withimplode(' ', array_unique($html)).validHtmlAttributes()method for backward compatibility — it now derives from the const.2.
FormAssetscore.jsis now read from disk once and held in astaticproperty, instead of on everycompileScripts()call.3.
FormMakerreadJavaScriptFile()helper backed by astaticcache sodefault.jsandvalidation.jsare read once per request. Per-call config string replacements are unchanged, so output is identical even when config differs between forms.Why
These run once per attribute / once per field / once per form render. On a typical multi-field form the
AttributeBuilderchange alone removes thousands of array allocations and linear scans per request; the asset changes remove redundant disk I/O when multiple forms render on a page.Reviewer notes
php -lclean on all three files, full suite green (174 tests, 354 assertions),pintpasses.🤖 Generated with Claude Code