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

JS Builtins #89

Open
vouillon opened this issue Oct 4, 2024 · 0 comments
Open

JS Builtins #89

vouillon opened this issue Oct 4, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@vouillon
Copy link
Collaborator

vouillon commented Oct 4, 2024

We are using a number of JavaScript functions to implement functionalities that are available in JavaScript but not directly in Wasm or for interoperability. We should make sure that they are well optimized. A way to achieve this is to push for proposals similar to the JS String Builtins to get them optimized. We could either champion other builtins proposals or at least help design them.

V8 currently has three mechanisms to optimize imported JavaScript functions.

  • For imported math functions, it generates a small Wasm function that implement it (I believe this function can then get inlined).
  • It recognizes imported functions such as Function.prototype.call.bind(DataView.prototype.getInt8) and generates inlined code (with Turboshaft).
  • The JS String Builtins proposal allows to import a standardized sets of functions to manipulate strings.

The latest mechanism seems best since it explicitly specifies which functions are expected to be optimized by the engine.

We would like these operations to be optimized:

  • UTF-8 encoding / decoding.
  • Math functions, from the Math object as well as the JavaScript remainder operator.
  • Functions to access array buffers.

Possibly also:

  • Conversion functions: between JS numbers and Wasm floats and i32, between booleans and i32.
  • Equality functions, method calls, array creation and access (I'm not sure this makes sense, though, since these are optimized in JS by tracing the execution and generating specialized code depending on what it really manipulated, which we probably don't want to to in Wasm).
  • Operations on Map and WeakMap objects.
  • BigInt operations (for zarith).

Regarding array buffers, the DataView API seems the simplest and most flexible (compared to support all the different kinds of typed arrays). One should probably add a way to read and write numbers using the native byte order so that one can reproduce typed array operations. One also needs a way to copy to and from a Wasm array.

@vouillon vouillon added the enhancement New feature or request label Oct 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant