From 2164f6b1eb7216c1045d547c94f26fe3ceaa9403 Mon Sep 17 00:00:00 2001 From: Aapo Alasuutari Date: Thu, 11 Aug 2022 16:56:56 +0300 Subject: perf(ops): Monomorphic sync op calls (#15337) Welcome to better optimised op calls! Currently opSync is called with parameters of every type and count. This most definitely makes the call megamorphic. Additionally, it seems that spread params leads to V8 not being able to optimise the calls quite as well (apparently Fast Calls cannot be used with spread params). Monomorphising op calls should lead to some improved performance. Now that unwrapping of sync ops results is done on Rust side, this is pretty simple: ``` opSync("op_foo", param1, param2); // -> turns to ops.op_foo(param1, param2); ``` This means sync op calls are now just directly calling the native binding function. When V8 Fast API Calls are enabled, this will enable those to be called on the optimised path. Monomorphising async ops likely requires using callbacks and is left as an exercise to the reader. --- core/lib.deno_core.d.ts | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'core/lib.deno_core.d.ts') diff --git a/core/lib.deno_core.d.ts b/core/lib.deno_core.d.ts index bd3729ed9..c5662794a 100644 --- a/core/lib.deno_core.d.ts +++ b/core/lib.deno_core.d.ts @@ -10,15 +10,13 @@ declare namespace Deno { /** Call an op in Rust, and synchronously receive the result. */ function opSync( opName: string, - a?: any, - b?: any, + ...args: any[] ): any; /** Call an op in Rust, and asynchronously receive the result. */ function opAsync( opName: string, - a?: any, - b?: any, + ...args: any[] ): Promise; /** Mark following promise as "ref", ie. event loop won't exit @@ -30,10 +28,10 @@ declare namespace Deno { function unrefOps(promiseId: number): void; /** - * Retrieve a list of all registered ops, in the form of a map that maps op + * List of all registered ops, in the form of a map that maps op * name to internal numerical op id. */ - function ops(): Record; + const ops: Record any>; /** * Retrieve a list of all open resources, in the form of a map that maps -- cgit v1.2.3