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

feat(ops): V8 Fast Calls #15291

Merged
merged 39 commits into from
Aug 21, 2022
Merged

feat(ops): V8 Fast Calls #15291

merged 39 commits into from
Aug 21, 2022

Conversation

littledivy
Copy link
Member

@littledivy littledivy commented Jul 23, 2022

Relands auto fast api template generation for ops. This optimization is opt in:

#[op(fast)]
fn something_mhmm(
  state: &mut OpState
) { 
  // mhmm
}
const { something_mhmm } = core.ops;
something_mhmm.fast(); // something_mhmm

@aapoalas

This comment was marked as outdated.

@littledivy littledivy added the ci-test-flaky put this on a PR to run concurrent workflows label Aug 5, 2022
@aapoalas

This comment was marked as resolved.

@littledivy littledivy marked this pull request as ready for review August 20, 2022 15:43
@littledivy littledivy changed the title [wip] feat(ops): reland V8 Fast Calls feat(ops): V8 Fast Calls Aug 20, 2022
@littledivy littledivy removed the ci-test-flaky put this on a PR to run concurrent workflows label Aug 20, 2022
cli/bench/deno_common.js Outdated Show resolved Hide resolved
cli/bench/deno_common.js Outdated Show resolved Hide resolved
core/bindings.rs Outdated Show resolved Hide resolved
core/bindings.rs Outdated Show resolved Hide resolved
core/bindings.rs Show resolved Hide resolved
core/bindings.rs Show resolved Hide resolved
core/extensions.rs Outdated Show resolved Hide resolved
core/extensions.rs Outdated Show resolved Hide resolved
core/runtime.rs Outdated Show resolved Hide resolved
core/runtime.rs Show resolved Hide resolved
@aapoalas
Copy link
Collaborator

I finally managed to understand that the fast bindings are generated to an extra function bound into the original function but... Why? Does the references snapshotting somehow not work with direct binding to the normal op call function?

for ctx in ops {
let ctx_ptr = ctx as *const OpCtx as _;
references.push(v8::ExternalReference { pointer: ctx_ptr });
references.push(v8::ExternalReference {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why are all this external refs now suddenly needed when previously they were not?

) {
for ctx in op_ctxs {
let ctx_ptr = ctx as *const OpCtx as *const c_void;
set_func_raw(scope, ops_obj, ctx.decl.name, ctx.decl.v8_fn_ptr, ctx_ptr);

// If this is a fast op, we don't want it to be in the snapshot.
Copy link
Collaborator

Choose a reason for hiding this comment

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

While this explains why the boolean is used here, it does not actually explain why the fast op is not wanted in the snapshot. At least I would like to understand why the fast op is left out: Is it because of the doubling of the OpCtx and slow call function pointer referencing?

@@ -1344,17 +1344,17 @@ async fn op_flash_next_async(
// the ContextScope creation is optimized away and the op is as simple as:
// f(info: *const v8::FunctionCallbackInfo) { let rv = ...; rv.set_uint32(op_flash_next()); }
#[op]
fn op_flash_next(op_state: &mut OpState) -> u32 {
let flash_ctx = op_state.borrow_mut::<FlashContext>();
fn op_flash_next(state: &mut OpState) -> u32 {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Unrelated changes?

Copy link
Member

@bartlomieju bartlomieju left a comment

Choose a reason for hiding this comment

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

LGTM

@littledivy littledivy merged commit 906aa78 into denoland:main Aug 21, 2022
@ry
Copy link
Member

ry commented Aug 22, 2022

This is awesome - great work @littledivy

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.

4 participants