Skip to content

Conversation

@CyanChanges
Copy link
Contributor

@CyanChanges CyanChanges commented May 6, 2025

#27217

op_runtime_cpu_usage can be optimized by accepting a &mut [u32] instead of returning a serde tuple but it can be done as a follow up.

Accept a &mut [u32] instead of serde tuple for op_runtime_cpu_usage and op_runtime_memory_usage

Copy link
Contributor Author

@CyanChanges CyanChanges left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need to move the buffer here outside to avoid allocate memory each time?

@CyanChanges CyanChanges marked this pull request as draft May 6, 2025 06:43
@CyanChanges CyanChanges marked this pull request as ready for review May 6, 2025 07:07
@0f-0b
Copy link
Contributor

0f-0b commented May 6, 2025

u32 isn't wide enough to hold all possible return values.

$ deno eval 'new Uint8Array(2 ** 32); console.log(Deno.memoryUsage())'
{
  rss: 43925504,
  heapTotal: 7340032,
  heapUsed: 6022768,
  external: 4298203118
}

@CyanChanges
Copy link
Contributor Author

CyanChanges commented May 6, 2025

u32 isn't wide enough to hold all possible return values.

$ deno eval 'new Uint8Array(2 ** 32); console.log(Deno.memoryUsage())'
{
  rss: 43925504,
  heapTotal: 7340032,
  heapUsed: 6022768,
  external: 4298203118
}

But it is not possible to use &mut [u64] in the ops i guess?

@CyanChanges
Copy link
Contributor Author

or maybe we need read bigints from the buffer and cast them back to numbers?

@CyanChanges
Copy link
Contributor Author

I checked Node.js's implementation, and now using Float64Array for this:
image

@CyanChanges CyanChanges requested a review from littledivy May 6, 2025 10:01
Copy link
Member

@littledivy littledivy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@littledivy littledivy merged commit 5cd03fe into denoland:main May 9, 2025
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants