mirror of
https://github.com/denoland/deno.git
synced 2025-09-26 12:19:12 +00:00
perf(fs): don't canonicalize path when opening file if --allow-all
is passed (#28716)
Fixes #28702. Super artificial benchmark: ```ts const perf = performance; async function asyncOpen() { const start = perf.now(); for (let i = 0; i < 100_000; i++) { const file = await Deno.open("./foo.txt"); file.close(); } const end = perf.now(); console.log(end - start); } function syncOpen() { const start = perf.now(); for (let i = 0; i < 100_000; i++) { const file = Deno.openSync("./foo.txt"); file.close(); } const end = perf.now(); console.log(end - start); } if (Deno.args[0]?.trim() === "async") { await asyncOpen(); } else { syncOpen(); } ``` Results (average of 10 for each): ``` deno sync 1785.59 deno-this-pr sync 491.69 deno async 1839.71 deno-this-pr async 528.78 ``` --------- Co-authored-by: David Sherret <dsherret@users.noreply.github.com>
This commit is contained in:
parent
1a171f10df
commit
c22d17824b
14 changed files with 205 additions and 134 deletions
|
@ -2610,13 +2610,13 @@ impl PermissionsContainer {
|
|||
#[inline(always)]
|
||||
pub fn check_read_path<'a>(
|
||||
&self,
|
||||
path: &'a Path,
|
||||
path: Cow<'a, Path>,
|
||||
api_name: Option<&str>,
|
||||
) -> Result<Cow<'a, Path>, PermissionCheckError> {
|
||||
let mut inner = self.inner.lock();
|
||||
let inner = &mut inner.read;
|
||||
if inner.is_allow_all() {
|
||||
Ok(Cow::Borrowed(path))
|
||||
Ok(path)
|
||||
} else {
|
||||
let desc = PathQueryDescriptor {
|
||||
requested: path.to_string_lossy().into_owned(),
|
||||
|
@ -2698,13 +2698,13 @@ impl PermissionsContainer {
|
|||
#[inline(always)]
|
||||
pub fn check_write_path<'a>(
|
||||
&self,
|
||||
path: &'a Path,
|
||||
path: Cow<'a, Path>,
|
||||
api_name: &str,
|
||||
) -> Result<Cow<'a, Path>, PermissionCheckError> {
|
||||
let mut inner = self.inner.lock();
|
||||
let inner = &mut inner.write;
|
||||
if inner.is_allow_all() {
|
||||
Ok(Cow::Borrowed(path))
|
||||
Ok(path)
|
||||
} else {
|
||||
let desc = PathQueryDescriptor {
|
||||
requested: path.to_string_lossy().into_owned(),
|
||||
|
@ -3396,6 +3396,10 @@ impl PermissionsContainer {
|
|||
),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn allows_all(&self) -> bool {
|
||||
matches!(self.inner.lock().all.state, PermissionState::Granted)
|
||||
}
|
||||
}
|
||||
|
||||
const fn unit_permission_from_flag_bools(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue