Skip to content

Conversation

jrflat
Copy link
Contributor

@jrflat jrflat commented Sep 12, 2025

During URL parsing, much of the time is spent validating the components in UInt8.allowedURLComponents.getter. We can make this faster by using allowed bit masks per component rather than relying on a switch statement for the UInt8 code units.

The added test checks the validation behavior for all UInt8 code units in each URL component. The test passes before and after this change.

20-25% speed up for parsing valid ASCII URLs:

URLValidationPerformance

// MARK: - String Parsing

Benchmark("URL-ParseValidASCII") { benchmark in
Benchmark("URL.ParseValidASCII") { benchmark in
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed the benchmark names to use . so they display better in the JMH visualizer.

@jrflat
Copy link
Contributor Author

jrflat commented Sep 12, 2025

@swift-ci please test

@jrflat jrflat merged commit 02c0494 into swiftlang:main Sep 15, 2025
19 checks passed
tshortli added a commit to tshortli/swift-foundation that referenced this pull request Sep 16, 2025
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