perf(runtime): bypass tokio file and bump op buffer size to 64K (#14319)

This commit is contained in:
Divy Srivastava 2022-04-19 20:11:31 +05:30 committed by GitHub
parent 3d1123f8b0
commit 1c05e41f37
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 113 additions and 162 deletions

View file

@ -8,7 +8,6 @@ use deno_core::error::AnyError;
use deno_core::op;
use deno_core::Extension;
use deno_core::OpState;
use deno_core::RcRef;
use deno_core::ResourceId;
use serde::Deserialize;
use serde::Serialize;
@ -96,28 +95,11 @@ fn op_set_raw(state: &mut OpState, args: SetRawArgs) -> Result<(), AnyError> {
return Err(bad_resource_id());
}
let fs_file_resource =
RcRef::map(&resource, |r| r.fs_file.as_ref().unwrap()).try_borrow_mut();
let handle_result = if let Some(mut fs_file) = fs_file_resource {
let tokio_file = fs_file.0.take().unwrap();
match tokio_file.try_into_std() {
Ok(std_file) => {
let raw_handle = std_file.as_raw_handle();
// Turn the std_file handle back into a tokio file, put it back
// in the resource table.
let tokio_file = tokio::fs::File::from_std(std_file);
fs_file.0 = Some(tokio_file);
// return the result.
Ok(raw_handle)
}
Err(tokio_file) => {
// This function will return an error containing the file if
// some operation is in-flight.
fs_file.0 = Some(tokio_file);
Err(resource_unavailable())
}
}
let handle_result = if let Some((fs_file, _)) = &resource.fs_file {
let file = fs_file.as_ref().unwrap().clone();
let std_file = file.lock().unwrap();
let raw_handle = std_file.as_raw_handle();
Ok(raw_handle)
} else {
Err(resource_unavailable())
};
@ -156,20 +138,15 @@ fn op_set_raw(state: &mut OpState, args: SetRawArgs) -> Result<(), AnyError> {
return Err(not_supported());
}
let maybe_fs_file_resource =
RcRef::map(&resource, |r| r.fs_file.as_ref().unwrap()).try_borrow_mut();
let (fs_file, meta) =
resource.fs_file.as_ref().ok_or_else(resource_unavailable)?;
if maybe_fs_file_resource.is_none() {
if fs_file.is_none() {
return Err(resource_unavailable());
}
let mut fs_file_resource = maybe_fs_file_resource.unwrap();
if fs_file_resource.0.is_none() {
return Err(resource_unavailable());
}
let raw_fd = fs_file_resource.0.as_ref().unwrap().as_raw_fd();
let maybe_tty_mode = &mut fs_file_resource.1.as_mut().unwrap().tty.mode;
let raw_fd = fs_file.as_ref().unwrap().lock().unwrap().as_raw_fd();
let maybe_tty_mode = &mut meta.as_ref().unwrap().borrow_mut().tty.mode;
if is_raw {
if maybe_tty_mode.is_none() {