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

perf: fs optimizations - part 1 #15873

Merged
merged 24 commits into from
Sep 22, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fixes
  • Loading branch information
littledivy committed Sep 20, 2022
commit 811187c93bb56d6d32ee02aac0cdcccb4d2cdf38
6 changes: 3 additions & 3 deletions runtime/js/30_fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@
}

function fstatSync(rid) {
ops.op_fstat_sync(rid, statBuf.buffer);
ops.op_fstat_sync(rid, statBuf);
return statStruct(statBuf);
}

Expand All @@ -305,7 +305,7 @@
ops.op_stat_sync(
pathFromURL(path),
true,
statBuf.buffer,
statBuf,
);
return statStruct(statBuf);
}
Expand All @@ -322,7 +322,7 @@
ops.op_stat_sync(
pathFromURL(path),
false,
statBuf.buffer,
statBuf,
);
return statStruct(statBuf);
}
Expand Down
14 changes: 3 additions & 11 deletions runtime/ops/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ async fn op_fsync_async(
fn op_fstat_sync(
state: &mut OpState,
rid: ResourceId,
out_buf: &mut [u8],
out_buf: &mut [u32],
) -> Result<(), AnyError> {
let metadata = StdFileResource::with_file(state, rid, |std_file| {
std_file.metadata().map_err(AnyError::from)
Expand Down Expand Up @@ -953,15 +953,7 @@ fn to_msec(maybe_time: Result<SystemTime, io::Error>) -> (u64, bool) {
macro_rules! create_struct_writer {
(pub struct $name:ident { $($field:ident: $type:ty),* $(,)? }) => {
impl $name {
fn write(self, buf: &mut [u8]) {
assert_eq!(buf.len() % std::mem::size_of::<u32>(), 0);
// SAFETY: size is multiple of 4
let buf = unsafe {
std::slice::from_raw_parts_mut(
buf.as_mut_ptr() as *mut u32,
buf.len() / std::mem::size_of::<u32>(),
)
};
fn write(self, buf: &mut [u32]) {
let mut offset = 0;
$(
let value = self.$field as u64;
Expand Down Expand Up @@ -1068,7 +1060,7 @@ fn op_stat_sync(
state: &mut OpState,
path: String,
lstat: bool,
out_buf: &mut [u8],
out_buf: &mut [u32],
) -> Result<(), AnyError> {
let path = PathBuf::from(&path);
state.borrow_mut::<Permissions>().read.check(&path)?;
Expand Down