diff --git a/lib/internal/url.js b/lib/internal/url.js index 81900c28fff5ec..510053ac259538 100644 --- a/lib/internal/url.js +++ b/lib/internal/url.js @@ -776,10 +776,11 @@ class URL { static { setURLSearchParamsModified = (obj) => { - // If URLSearchParams gets updated, use that as the source-of-truth for search. + // When URLSearchParams changes, we lazily update URL on the next read/write for performance. obj.#searchParamsModified = true; - // If URL has an existing search, remove it without cascading back to URLSearchParams + // If URL has an existing search, remove it without cascading back to URLSearchParams. + // Do this to avoid any internal confusion about whether URLSearchParams or URL is up-to-date. if (obj.#context.hasSearch) { obj.#updateContext(bindingUrl.update(obj.#context.href, updateActions.kSearch, ''), false); } @@ -845,7 +846,8 @@ class URL { } #checkSearchParams() { - // If URLSearchParams has been modified, reflect that back into URL. + // If URLSearchParams has been modified, reflect that back into URL, and do not cascade back. + // This is done lazily to greatly improve performance when URLSearchParams is updated repeatedly. if (this.#searchParamsModified) { const href = bindingUrl.update(this.#context.href, updateActions.kSearch, this.#getSearchFromParams()); this.#updateContext(href, false);