Skip to content

Forms: cut per-control overhead in submit, validation and rendering - #1

Open
ohmyfelix wants to merge 1 commit into
masterfrom
perf/r3-per-control
Open

ohmyfelix wants to merge 1 commit into
masterfrom
perf/r3-per-control

Conversation

@ohmyfelix

Copy link
Copy Markdown
Collaborator

What

  • TextBase::getValue() skips translate + trim when emptyValue === '' (same guard getControl() already uses).
  • Single-pass Rules::getIterator(); Operations::toValidator() dispatches on the operation directly instead of match(true) with a closure.
  • MessageFormatter returns early for messages without %; Validation\Message skips uksort for fewer than 2 parameters; BaseControl::getErrors() returns early.
  • DefaultFormRenderer::getValue() memoizes the split wrapper key.

Why

These run per control, several times per submit and render.

Measured

30-control form, PHP 8.5, warm (tracing JIT): submit (build + validate + getValues) 221 -> 158 us (-28 %), render POST 601 -> 498 us (-17 %), render GET 474 -> 425 us, build -7..-9 %. Cold (fresh process): POST form 2227 -> 2061 us min (-7.5 %), GET 1797 -> 1761 us.
Measured together with the nette/component-model monitor PR; this PR alone excludes it.
Equivalence: rendered HTML, errors and values byte-identical for valid and invalid POST; toValidator() checked on 13 440 op/arg/control cases including exceptions.

Details: https://github.com/subnette/rfc-performance/blob/perf/round-2/docs/perf/round-2.md (round 3 numbers measured on current upstream master).

Tests

  • vendor/bin/tester tests -s -C on master: OK (123 tests)
  • same on this branch: OK (123 tests)
  • phpstan: no errors on both

No behaviour change intended. A subclass overriding translate() to turn '' into a non-empty string would see a difference in getValue().

TextBase::getValue() skips translate+trim for an empty emptyValue (as getControl() already does); single-pass Rules iterator; MessageFormatter returns early without %; Message skips uksort for fewer than 2 parameters; renderer memoizes split wrapper keys; Operations::toValidator() dispatches on the operation directly; BaseControl::getErrors() returns early.
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