Skip to content

Conversation

@AnsisMalins
Copy link
Contributor

This change adds a new Uint8Array type that mirrors the V8's type. It is a readonly ref struct. The use case is to retrieve it and pass it around inside the calling code for some small distance until its contents can be copied out to a byte[] array.

By itself, this change does no avoid the allocation of a V8ObjectImpl as that still happens in V8FastArgs.ctor.

@ClearScriptLib
Copy link
Collaborator

Hi @AnsisMalins,

Some observations:

  • Is this a complete change? The new code in V8FastArgs.cs appears to call a new V8FastArgImpl method, but the commit doesn't include V8FastArgImpl.cs.
  • We strongly believe in API consistency and uniformity, whereas this change seems to be a minimal one tailored specifically for your use case. For example, it only supports a minimal set of operations, only for byte arrays, and only in V8FastArgs (as opposed to the singular V8FastArg).
  • This API is fragile, as instances of the new type are valid only during the call and could crash if saved and used later.

We do like this idea in general, as ClearScript already provides special treatment for typed arrays elsewhere. Typed arrays were designed for performance-critical scenarios. Can you tell us anything about yours?

Thanks!

@AnsisMalins AnsisMalins marked this pull request as draft October 17, 2025 07:21
@AnsisMalins
Copy link
Contributor Author

AnsisMalins commented Oct 17, 2025

Yes, I missed a file there. Oops!

The specific case I'm trying to solve is, JavaScript code sends new byte arrays to C# side many times per frame, 60 frames per second. As is, for every JavaScript object a V8ObjectImpl is created on the C# side, and I'm trying to bring allocations per frame down to zero. I have limited control over the JavaScript side, so I can't ensure it reuses a small amount JavaScript objects.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants