Skip to content

Commit ff91c2d

Browse files
committed
perf(runtime/ops): use tuple instead of object
1 parent e24b009 commit ff91c2d

File tree

3 files changed

+20
-36
lines changed

3 files changed

+20
-36
lines changed

ext/os/README.md

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,8 @@ This crate implements OS specific APIs for Deno
3535

3636
`cpu_usage`
3737

38-
| Target family | Syscall | Description |
39-
| ------------- |------------------------------------------------| ----------- |
40-
| Linux | getrusage | - |
41-
| Windows | `processthreadsapi::GetProcessTimes` | - |
42-
| macOS | getrusage | - |
43-
44-
38+
| Target family | Syscall | Description |
39+
| ------------- | ------------------------------------ | ----------- |
40+
| Linux | getrusage | - |
41+
| Windows | `processthreadsapi::GetProcessTimes` | - |
42+
| macOS | getrusage | - |

ext/os/lib.rs

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -422,20 +422,11 @@ fn op_uid(state: &mut OpState) -> Result<Option<u32>, PermissionCheckError> {
422422
Ok(None)
423423
}
424424

425-
#[derive(Serialize)]
426-
struct CpuUsage {
427-
system: usize,
428-
user: usize,
429-
}
430-
431425
#[op2]
432426
#[serde]
433-
fn op_runtime_cpu_usage() -> CpuUsage {
427+
fn op_runtime_cpu_usage() -> (usize, usize) {
434428
let (sys, user) = get_cpu_usage();
435-
CpuUsage {
436-
system: sys.as_micros() as usize,
437-
user: user.as_micros() as usize,
438-
}
429+
(sys.as_micros() as usize, user.as_micros() as usize)
439430
}
440431

441432
#[cfg(unix)]
@@ -536,27 +527,22 @@ fn get_cpu_usage() -> (std::time::Duration, std::time::Duration) {
536527
Default::default()
537528
}
538529

539-
// HeapStats stores values from a isolate.get_heap_statistics() call
540-
#[derive(Serialize)]
541-
#[serde(rename_all = "camelCase")]
542-
struct MemoryUsage {
543-
rss: usize,
544-
heap_total: usize,
545-
heap_used: usize,
546-
external: usize,
547-
}
548-
549530
#[op2]
550531
#[serde]
551-
fn op_runtime_memory_usage(scope: &mut v8::HandleScope) -> MemoryUsage {
532+
fn op_runtime_memory_usage(
533+
scope: &mut v8::HandleScope,
534+
) -> (usize, usize, usize, usize) {
552535
let mut s = v8::HeapStatistics::default();
553536
scope.get_heap_statistics(&mut s);
554-
MemoryUsage {
555-
rss: rss(),
556-
heap_total: s.total_heap_size(),
557-
heap_used: s.used_heap_size(),
558-
external: s.external_memory(),
559-
}
537+
538+
let (rss, heap_total, heap_used, external) = (
539+
rss(),
540+
s.total_heap_size(),
541+
s.used_heap_size(),
542+
s.external_memory(),
543+
);
544+
545+
(rss, heap_total, heap_used, external)
560546
}
561547

562548
#[cfg(any(target_os = "android", target_os = "linux"))]

runtime/js/90_deno_ns.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ const denoNs = {
6666
memoryUsage: () => {
6767
const { 0: rss, 1: heapTotal, 2: heapUsed, 3: external } =
6868
op_runtime_memory_usage();
69-
return { rss, heapTotal, heapUsed, external };
69+
return { rss, heapTotal, heapUsed, external, arrayBuffers: 0 };
7070
},
7171
mkdirSync: fs.mkdirSync,
7272
mkdir: fs.mkdir,

0 commit comments

Comments
 (0)