[LiveComponent] Skip the bracket pipeline for plain model names - #3786
Open
Kocal wants to merge 1 commit into
Open
[LiveComponent] Skip the bracket pipeline for plain model names#3786Kocal wants to merge 1 commit into
Kocal wants to merge 1 commit into
Conversation
| Q | A
| -------------- | ---
| Bug fix? | no
| New feature? | no
| Deprecations? | no
| Documentation? | no
| Issues | -
| License | MIT
`normalizeModelName()` ran a `replace()`, a `split()`, a `map()` with a
second `replace()` per part and a `join()` on every call, even for a plain
name like `query` where the whole pipeline is a no-op.
It runs on every input event through `getValueFromElement()`, and twice per
`ValueStore.set()` since `set()` normalizes and then calls `get()`, which
normalizes again.
Return the name untouched when it contains neither `[` nor `]`. Names that
do use the bracket syntax take the same path as before.
400k calls: plain names ~45 ms -> ~12 ms, a realistic 80/20 mix ~43 ms ->
~17 ms, bracketed names unchanged (~84 ms). These are micro-seconds per
event in absolute terms, but the change is three lines and output is
identical.
Browser-side JavaScript, so there is no Blackfire profile for this one.
Benchmarked on node 22 with `node bench.mjs`, comparing both
implementations side by side:
```js
function current(model) {
return model.replace(/\[]$/, '').split('[').map((s) => s.replace(']', '')).join('.');
}
function candidate(model) {
if (!model.includes('[') && !model.includes(']')) {
return model;
}
return model.replace(/\[]$/, '').split('[').map((s) => s.replace(']', '')).join('.');
}
const plain = ['firstName', 'email', 'query', 'isEnabled', 'selectedId'];
const bracketed = ['user[firstName]', 'user[mailing][]', 'form[items][0][label]'];
for (const [label, names] of [
['plain only', plain],
['bracketed only', bracketed],
['mixed 80/20', [...plain, ...plain, ...plain, ...plain, ...bracketed]],
]) {
for (const [impl, fn] of [['current', current], ['candidate', candidate]]) {
for (const n of names) fn(n); // warm up
const start = process.hrtime.bigint();
for (let i = 0; i < 400000; i++) {
fn(names[i % names.length]);
}
console.log(`${label} ${impl} -> ${(Number(process.hrtime.bigint() - start) / 1e6).toFixed(2)} ms`);
}
}
```
A stray `]` with no `[` was the one input where the fast path could have
diverged, so it is now covered by a unit test.
Analysis, implementation and benchmarks by Claude Opus 5.
Contributor
📊 Packages dist files size differenceThanks for the PR! Here is the difference in size of the packages dist files between the base branch and the PR.
|
|||||||||
smnandre
reviewed
Aug 15, 2026
Comment on lines
+34
to
+35
| // Most model names are plain (e.g. "query"), and the pipeline below is a | ||
| // no-op for them. ValueStore also normalizes already-normalized names. |
Member
There was a problem hiding this comment.
Suggested change
| // Most model names are plain (e.g. "query"), and the pipeline below is a | |
| // no-op for them. ValueStore also normalizes already-normalized names. | |
| // Some model names are plain (e.g. "query") |
Because with LiveComponent and live form, most model names are prefixed by their form name prefix, like that: myform[foo].
smnandre
approved these changes
Aug 15, 2026
smnandre
left a comment
Member
There was a problem hiding this comment.
Let's not add misleading comments
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.
normalizeModelName()ran areplace(), asplit(), amap()with a secondreplace()per part and ajoin()on every call, even for a plain name likequerywhere the whole pipeline is a no-op.It runs on every input event through
getValueFromElement(), and twice perValueStore.set()sinceset()normalizes and then callsget(), which normalizes again.Return the name untouched when it contains neither
[nor]. Names that do use the bracket syntax take the same path as before.Measured over 400k calls, alternating both implementations to cancel any warm-up ordering effect:
So it costs about 2% on a page that's nothing but live form fields, and pays off as soon as any plain model name is in the mix. In absolute terms this is nanoseconds per keystroke either way; the change is three lines and output is identical.
Browser-side JavaScript, so there is no Blackfire profile for this one. Benchmarked on node 22 with
node bench.mjs, comparing both implementations side by side:A stray
]with no[was the one input where the fast path could have diverged, so it is now covered by a unit test.Analysis, implementation and benchmarks by Claude Opus 5.