Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net.urllib: cleanup parse_authority, add test #21599

Merged
merged 4 commits into from
May 29, 2024

Conversation

ttytm
Copy link
Member

@ttytm ttytm commented May 29, 2024

Updates the internal urllib function parse_authority that is used by the public parse function. Adds tests.

As far as I could tell the current implementation was based of Go's implementation, which has a different error handling. With V it was possible to make the code more readable while managing to slightly improve the performance at the same time.

Performance test:
❯ v repeat -r 20 benchmarks/pa_gcc_new benchmarks/pa_gcc_old
Summary after 1 series x 20 runs (`>` is the first cmd)                                                                                                                            
 >  1       === `benchmarks/pa_gcc_new`
                232.0ms ± σ:   6.6ms, 224.8ms … 254.0ms
    2     +2.5% `benchmarks/pa_gcc_old`
                237.7ms ± σ:   4.3ms, 231.8ms … 251.2ms
❯ v repeat -r 20 benchmarks/pa_clang_new benchmarks/pa_clang_old
Summary after 1 series x 20 runs (`>` is the first cmd)                                                                                                                            
 >  1       === `benchmarks/pa_clang_new`
                206.1ms ± σ:   2.2ms, 202.2ms … 210.2ms
    2     +1.4% `benchmarks/pa_clang_old`
                209.0ms ± σ:   2.7ms, 204.9ms … 215.4ms
import net.urllib

fn main() {
	test_urls := [
		'https://joe:[email protected]:8080/som/url?param1=test1&param2=test2&foo=bar#testfragment',
		'ftp://[email protected]/',
		'http://j@ne:[email protected]',
		'http://jane:p@[email protected]/p@th?q=@go',
	]

	for _ in 0 .. 100_000 {
		for url in test_urls {
			urllib.parse(url)!
		}
	}
}

Copy link
Member

@spytheman spytheman left a comment

Choose a reason for hiding this comment

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

Excellent work.

@spytheman spytheman merged commit ea20c1f into vlang:master May 29, 2024
64 checks passed
@ttytm ttytm deleted the urllib/update-parse-auth branch May 29, 2024 23:30
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