Skip to content

perf: avoid quadratic remote form issue merging - #16493

Merged
Rich-Harris merged 2 commits into
sveltejs:version-3from
Nic-Polumeyv:form-issue-merge
Jul 29, 2026
Merged

Rich-Harris merged 2 commits into
sveltejs:version-3from
Nic-Polumeyv:form-issue-merge

Conversation

@Nic-Polumeyv

@Nic-Polumeyv Nic-Polumeyv commented Jul 23, 2026 •

Copy link
Copy Markdown
Member

merge_with_server_issues runs whenever preflight validation produces issues, which with the documented oninput pattern means on every keystroke while a form has issues. Merging costs O(S·C + M·K·log M) for S server issues, C client issues, M merged issues and K form keys. 🤓 This change drops it to O(S + C + K + M·log M). 🤓

N fields with N issues (half server, half client), Node 22 x64, median of repeated runs:

fields before after speedup
400 1.6 ms 0.1 ms 15×
800 7.9 ms 0.3 ms 27×
1600 33.0 ms 0.8 ms 42×
3200 163.8 ms 2.2 ms 76×

Small forms are at parity or slightly faster, since the old code already allocated the key array.

Output is unchanged: identical issue-object ordering to the previous implementation across 10,000 randomized cases covering duplicated form keys, duplicated issue names, names absent from the form, mixed server and client issues and empty collections. The merge semantics negotiated in #14744/#14759 are preserved.


Before submitting the PR, please make sure you do the following

Tests

  • Run the tests with pnpm test and lint the project with pnpm lint and pnpm check

Changesets

  • If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running pnpm changeset and following the prompts. Changesets that add features should be minor and those that fix bugs should be patch. Please prefix changeset messages with feat:, fix:, or chore:.

Loading
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