perf(node_resolver): reduce url to/from path conversions (#27839)

Extracted out of https://github.com/denoland/deno/pull/27838/files

Reduces some allocations by accepting either a pathbuf or url for the
referrer for resolution and returning either a pathbuf or url at the
end, which the caller can then convert into to their preferred state.

This is about 4% faster when still converting the final result to a url
and 6% faster when keeping the result as a path in a benchmark I ran.
This commit is contained in:
David Sherret 2025-01-27 15:23:20 -05:00 committed by GitHub
parent 92dce12af7
commit 679902a108
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
28 changed files with 679 additions and 417 deletions

View file

@ -667,7 +667,12 @@ impl<TGraphContainer: ModuleGraphContainer>
ResolutionMode::Import,
NodeResolutionKind::Execution,
)
.map_err(|e| JsErrorBox::from_err(e).into());
.map_err(|e| JsErrorBox::from_err(e).into())
.and_then(|url_or_path| {
url_or_path
.into_url()
.map_err(|e| JsErrorBox::from_err(e).into())
});
}
}
@ -696,6 +701,8 @@ impl<TGraphContainer: ModuleGraphContainer>
source,
})
})?
.into_url()
.map_err(JsErrorBox::from_err)?
}
Some(Module::Node(module)) => module.specifier.clone(),
Some(Module::Js(module)) => module.specifier.clone(),