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

perf: optimize URL serialization #15663

Merged
merged 15 commits into from
Sep 10, 2022
Merged

Conversation

littledivy
Copy link
Member

@littledivy littledivy commented Aug 29, 2022

2.4x improvement in (new URL(path)).pathname.

# main
deno run -A --unstable cli/bench/url_parse.js 3 1000000
time 1080 ms rate 925925
time 1064 ms rate 939849
time 1048 ms rate 954198

# this patch
target/release/deno run -A --unstable cli/bench/url_parse.js 3 1000000
time 444 ms rate 2252252
time 429 ms rate 2331002
time 474 ms rate 2109704

ext/url/00_url.js Outdated Show resolved Hide resolved
Copy link
Member Author

@littledivy littledivy left a comment

Choose a reason for hiding this comment

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

Blocked on servo/rust-url#788

@littledivy littledivy marked this pull request as ready for review September 9, 2022 15:24
Copy link
Member

@lucacasonato lucacasonato left a comment

Choose a reason for hiding this comment

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

Looks great!

ext/url/00_url.js Show resolved Hide resolved
Copy link
Member

@lucacasonato lucacasonato left a comment

Choose a reason for hiding this comment

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

Can you add a comment explaining how op_url_parse, op_url_get_serialization, and op_url_parse_with_base interact? Would be very helpful for future readers. After that, LGTM!

ext/url/lib.rs Outdated Show resolved Hide resolved
return core.ops.op_url_get_serialization();
} else {
throw new TypeError("Invalid URL");
}
}

class URLSearchParams {
Copy link
Contributor

Choose a reason for hiding this comment

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

i did some benchmarking and there is a small change we can make here that passes all the wpt tests and bumps perf by 15-20% when api consumer accesses searchParams getter on URL and there are no query params, which is likely the common case. i can do this in a separate PR if you like as i think there are a few other small wins we can find here.

Screenshot from 2022-09-09 23-31-31

Copy link
Contributor

Choose a reason for hiding this comment

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

actually, we could just move that up to the top of the function i think?

Copy link
Member Author

Choose a reason for hiding this comment

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

Nice find!

i can do this in a separate PR

yup, that'll be great

@littledivy littledivy merged commit a54d565 into denoland:main Sep 10, 2022
cjihrig pushed a commit that referenced this pull request Sep 15, 2022
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.

4 participants