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

πŸ› Bug Report β€” Runtime APIs: URL.searchParams performance issue #1903

Open
MattIPv4 opened this issue Mar 26, 2024 · 0 comments
Open

Comments

@MattIPv4
Copy link

MattIPv4 commented Mar 26, 2024

πŸ‘‹ It seems that workerd suffers from the same performance issue that I fixed in Node.js (nodejs/node#51520), where repeat writes to URL.searchParams trigger URL to re-parse the params on every write, leading to a performance bottleneck.

This can be seen in the Workers playground:

export default {
	async fetch(request, env, ctx) {
		const url = new URL(request.url);
		
		if (url.pathname === '/url') {
			const params = new URL(request.url).searchParams;
			for (let i = 0; i < 100_000; i++) params.append('test', i.toString());
		}

		if (url.pathname === '/urlsearchparams') {
			const params = new URLSearchParams();
			for (let i = 0; i < 100_000; i++) params.append('test', i.toString());
		}

		return Response.json({ ok: true });
	},
};

A request to /url will time out, but a request to /urlsearchparams runs without issue.

I suspect a patch similar to what I landed in Node.js, where URL is lazily updated if searchParams has changed the next time a getter is called, rather than immediately updating URL when searchParams changes, would fix it.

Alas, I'm not confident enough w/ C++ and this codebase to submit a patch myself I suspect -- perhaps if someone can point me in the direction of where URLSearchParams talks back to URL, I might be able to figure it out from there?

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

No branches or pull requests

1 participant