#deno #ops #proc-macro #macro #op #proc #register

macro deno_ops

Proc macro for writing Deno Ops

30 breaking releases

Uses new Rust 2021

new 0.31.0 Sep 28, 2022
0.29.0 Sep 15, 2022
0.23.0 Jul 28, 2022
0.5.0 Mar 31, 2022

#170 in Procedural macros

Download history 1532/week @ 2022-06-12 1568/week @ 2022-06-19 1892/week @ 2022-06-26 1838/week @ 2022-07-03 1789/week @ 2022-07-10 2332/week @ 2022-07-17 2106/week @ 2022-07-24 2775/week @ 2022-07-31 2600/week @ 2022-08-07 2815/week @ 2022-08-14 3216/week @ 2022-08-21 3455/week @ 2022-08-28 3663/week @ 2022-09-04 4238/week @ 2022-09-11 4429/week @ 2022-09-18 3932/week @ 2022-09-25

16,513 downloads per month
Used in 38 crates (via deno_core)

MIT license

36KB
959 lines

deno_ops

proc_macro for generating highly optimized V8 functions from Deno ops.

// Declare an op.
#[op(fast)]
pub fn op_add(_: &mut OpState, a: i32, b: i32) -> i32 {
  a + b
}

// Register with an extension.
Extension::builder()
  .ops(vec![op_add::decl()])
  .build();

Performance

The macro can optimize away code, short circuit fast paths and generate a Fast API impl.

Cases where code is optimized away:

  • -> () skips serde_v8 and rv.set calls.
  • -> Result<(), E> skips serde_v8 and rv.set calls for Ok() branch.
  • -> ResourceId or -> [int] types will use specialized method like v8::ReturnValue::set_uint32. A fast path for SMI.
  • -> Result<ResourceId, E> or -> Result<[int], E> types will be optimized like above for the Ok() branch.

Fast calls

The macro will infer and try to auto generate V8 fast API call trait impl for sync ops with:

  • arguments: integers, bool, &mut OpState, &[u8], &mut [u8],&[u32],&mut [u32]`
  • return_type: integers, bool

The #[op(fast)] attribute should be used to enforce fast call generation at compile time.

Trait gen for async ops & a ZeroCopyBuf equivalent type is planned and will be added soon.

Dependencies

~1.5–2.5MB
~64K SLoC