Skip to content

Simplify NameValidation by using contains and containsOnly#65869

Merged
webkit-commit-queue merged 1 commit into
WebKit:mainfrom
annevk:eng/Simplify-NameValidation-by-using-contains-and-containsOnly
Jun 5, 2026
Merged

Simplify NameValidation by using contains and containsOnly#65869
webkit-commit-queue merged 1 commit into
WebKit:mainfrom
annevk:eng/Simplify-NameValidation-by-using-contains-and-containsOnly

Conversation

@annevk
Copy link
Copy Markdown
Contributor

@annevk annevk commented May 28, 2026

dd8ad14

Simplify NameValidation by using contains and containsOnly
https://bugs.webkit.org/show_bug.cgi?id=315737
rdar://178698891

Reviewed by Ryosuke Niwa and Darin Adler.

This does result in the first code unit being checked twice for the
checks that have special rules for the first code unit, but using
substring seemed more expensive. And using contains and containsOnly
should be more efficient as there's less is8Bit branching.

Tested neutral on Speedometer.

Canonical link: https://commits.webkit.org/314632@main

f37ad0e

Misc iOS, visionOS, tvOS & watchOS macOS Linux Windows Apple Internal
✅ 🧪 style ✅ 🛠 ios ✅ 🛠 mac ✅ 🛠 wpe ✅ 🛠 win ⏳ 🛠 ios-apple
✅ 🧪 bindings ✅ 🛠 ios-sim ✅ 🛠 mac-AS-debug ✅ 🧪 wpe-wk2 🧪 win-tests ⏳ 🛠 mac-apple
✅ 🧪 webkitperl ✅ 🧪 ios-wk2 ✅ 🧪 api-mac ✅ 🧪 api-wpe ⏳ 🛠 vision-apple
✅ 🧪 ios-wk2-wpt ✅ 🧪 api-mac-debug ✅ 🛠 gtk3-libwebrtc
❌ 🧪 api-ios ✅ 🧪 mac-wk1 ✅ 🛠 gtk
✅ 🛠 ios-safer-cpp ✅ 🧪 mac-wk2 ✅ 🧪 gtk-wk2
✅ 🛠 vision ✅ 🧪 mac-AS-debug-wk2 ✅ 🧪 api-gtk
✅ 🛠 vision-sim ✅ 🧪 mac-wk2-stress ✅ 🛠 playstation
✅ 🛠 🧪 unsafe-merge ✅ 🧪 vision-wk2 ✅ 🧪 mac-intel-wk2
✅ 🛠 tv ✅ 🛠 mac-safer-cpp
✅ 🛠 tv-sim ❌ 🧪 mac-site-isolation
✅ 🛠 watch
✅ 🛠 watch-sim

@annevk annevk self-assigned this May 28, 2026
@annevk annevk added the DOM For bugs specific to XML/HTML DOM elements (including parsing). label May 28, 2026
@webkit-early-warning-system

This comment was marked as outdated.

@webkit-ews-buildbot

This comment was marked as outdated.

@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label May 28, 2026
@webkit-ews-buildbot

This comment was marked as outdated.

@annevk annevk removed the merging-blocked Applied to prevent a change from being merged label May 31, 2026
@annevk annevk force-pushed the eng/Simplify-NameValidation-by-using-contains-and-containsOnly branch from 18921ee to df99d30 Compare May 31, 2026 05:00
@webkit-early-warning-system

This comment was marked as outdated.

@webkit-ews-buildbot

This comment was marked as outdated.

@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label May 31, 2026
@annevk annevk removed the merging-blocked Applied to prevent a change from being merged label May 31, 2026
@annevk annevk force-pushed the eng/Simplify-NameValidation-by-using-contains-and-containsOnly branch from df99d30 to f3165a8 Compare May 31, 2026 06:26
@webkit-early-warning-system

This comment was marked as outdated.

@webkit-ews-buildbot

This comment was marked as outdated.

@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label May 31, 2026
@annevk annevk removed the merging-blocked Applied to prevent a change from being merged label Jun 1, 2026
@annevk annevk force-pushed the eng/Simplify-NameValidation-by-using-contains-and-containsOnly branch from f3165a8 to 2afe329 Compare June 1, 2026 12:16
@annevk annevk marked this pull request as ready for review June 1, 2026 12:47
@annevk annevk requested review from cdumez and rniwa as code owners June 1, 2026 12:47
@annevk annevk requested a review from darinadler June 1, 2026 12:47
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Jun 1, 2026
Copy link
Copy Markdown
Member

@rniwa rniwa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably perf A/B test this change with at least 20 iterations on macOS and iOS.

Copy link
Copy Markdown
Member

@darinadler darinadler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that we should check performance on this. It seems likely that having a separate branch for 8-bit will make this faster, so it’s possible the new version is faster!

return true;
}
if (isASCIIAlpha(firstCharacter))
return !name.contains(isInvalidElementNameCharacterAfterAlphaStart);
Copy link
Copy Markdown
Member

@darinadler darinadler Jun 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This re-checks the first character. The old code skipped that first character. That might not have been an important optimization, but it was intentional. We could keep that optimization by using name.substring(1) instead of name.

I see now that you said “using substring seemed more expensive”. What does “seemed” mean here? Is that a guess about performance or about code size?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It’s a guess. Cost of a StringView vs checking an additional code unit.

return true;
}
if (firstCharacter == ':' || firstCharacter == '_' || firstCharacter >= 0x80)
return name.containsOnly<isValidElementNameContinuationCharacter>();
Copy link
Copy Markdown
Member

@darinadler darinadler Jun 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This re-checks the first character. The old code skipped that first character. That might not have been an important optimization, but it was intentional. We could keep that optimization by using name.substring(1) instead of name.

I see now that you said “using substring seemed more expensive”. What does “seemed” mean here? Is that a guess about performance or about code size?

return false;
}
return true;
return name.containsOnly<isValidASCIIXMLNamePart>();
Copy link
Copy Markdown
Member

@darinadler darinadler Jun 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This re-checks the first character. The old code skipped that first character. That might not have been an important optimization, but it was intentional. We could keep that optimization by using name.substring(1) instead of name.

I see now that you said “using substring seemed more expensive”. What does “seemed” mean here? Is that a guess about performance or about code size?

@annevk annevk removed the merging-blocked Applied to prevent a change from being merged label Jun 5, 2026
@annevk annevk force-pushed the eng/Simplify-NameValidation-by-using-contains-and-containsOnly branch from 2afe329 to f37ad0e Compare June 5, 2026 09:18
@annevk annevk added the safe-merge-queue Applied to automatically send a pull-request to merge-queue after passing EWS checks label Jun 5, 2026
@webkit-ews-buildbot
Copy link
Copy Markdown
Collaborator

Failed api-ios checks. Please resolve failures and re-apply safe-merge-queue label.

Rejecting #65869 from merge queue.

@webkit-ews-buildbot webkit-ews-buildbot added merging-blocked Applied to prevent a change from being merged and removed safe-merge-queue Applied to automatically send a pull-request to merge-queue after passing EWS checks labels Jun 5, 2026
@webkit-ews-buildbot
Copy link
Copy Markdown
Collaborator

Safe-Merge-Queue: Build #94573.

@annevk annevk added unsafe-merge-queue Applied to send a pull request to merge-queue, but skip building and testing and removed merging-blocked Applied to prevent a change from being merged labels Jun 5, 2026
https://bugs.webkit.org/show_bug.cgi?id=315737
rdar://178698891

Reviewed by Ryosuke Niwa and Darin Adler.

This does result in the first code unit being checked twice for the
checks that have special rules for the first code unit, but using
substring seemed more expensive. And using contains and containsOnly
should be more efficient as there's less is8Bit branching.

Tested neutral on Speedometer.

Canonical link: https://commits.webkit.org/314632@main
@webkit-commit-queue webkit-commit-queue force-pushed the eng/Simplify-NameValidation-by-using-contains-and-containsOnly branch from f37ad0e to dd8ad14 Compare June 5, 2026 13:50
@webkit-commit-queue
Copy link
Copy Markdown
Collaborator

Committed 314632@main (dd8ad14): https://commits.webkit.org/314632@main

Reviewed commits have been landed. Closing PR #65869 and removing active labels.

@webkit-commit-queue webkit-commit-queue merged commit dd8ad14 into WebKit:main Jun 5, 2026
@webkit-commit-queue webkit-commit-queue removed the unsafe-merge-queue Applied to send a pull request to merge-queue, but skip building and testing label Jun 5, 2026
@annevk annevk deleted the eng/Simplify-NameValidation-by-using-contains-and-containsOnly branch June 5, 2026 13:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

DOM For bugs specific to XML/HTML DOM elements (including parsing).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants