Skip to content

Commit 1ba1683

Browse files
committed
perf: reduce the overhead of binding function call (#139)
* perf: reduce the overhead of binding function call * cache callback info object in scope * reduce closure variables captured in binding function that results 1.4x fast * MIN_CHROME_VERSION 85
1 parent 5e5d0ab commit 1ba1683

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

packages/emnapi/src/internal.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,11 @@ export function emnapiCreateFunction<F extends (...args: any[]) => any> (envObje
1717
return napiCallback(envObject.id, envObject.ctx.scopeStore.currentScope.id)
1818
}
1919

20-
const makeFunction = (envObject: Env, callback: (env: Env) => any) => function (this: any): any {
21-
'use strict'
20+
const makeFunction = (envObject: Env, callback: (env: Env) => any) => function (this: any, ...args: any[]): any {
2221
const scope = envObject.ctx.openScope(envObject)
2322
const callbackInfo = scope.callbackInfo
2423
callbackInfo.data = data
25-
callbackInfo.args = arguments
24+
callbackInfo.args = args
2625
callbackInfo.thiz = this
2726
callbackInfo.fn = f
2827
try {

0 commit comments

Comments
 (0)