Skip to content

Commit d4ef6da

Browse files
perf: reduce WASM boundary crossings in JS extractor
Gate extractCallbackDefinition behind member_expression type check to skip ~60-70% of calls on simple foo() expressions. Pass pre-read fn node to avoid redundant childForFieldName. Remove dead member_expression branch in extractReceiverName that read a property field only to return the same fallback value. Together these eliminate 3-4 WASM boundary crossings per call_expression node, targeting the 32% WASM regression between v2.0.0 and v2.1.0. Impact: 4 functions changed, 2 affected
1 parent 2312c92 commit d4ef6da

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

src/extractors/javascript.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,11 @@ export function extractSymbols(tree, _filePath) {
139139
if (callInfo) {
140140
calls.push(callInfo);
141141
}
142+
if (fn.type === 'member_expression') {
143+
const cbDef = extractCallbackDefinition(node, fn);
144+
if (cbDef) definitions.push(cbDef);
145+
}
142146
}
143-
const cbDef = extractCallbackDefinition(node);
144-
if (cbDef) definitions.push(cbDef);
145147
break;
146148
}
147149

@@ -320,10 +322,6 @@ function extractReceiverName(objNode) {
320322
if (objNode.type === 'identifier') return objNode.text;
321323
if (objNode.type === 'this') return 'this';
322324
if (objNode.type === 'super') return 'super';
323-
if (objNode.type === 'member_expression') {
324-
const prop = objNode.childForFieldName('property');
325-
if (prop) return objNode.text;
326-
}
327325
return objNode.text;
328326
}
329327

@@ -432,8 +430,8 @@ const EXPRESS_METHODS = new Set([
432430
]);
433431
const EVENT_METHODS = new Set(['on', 'once', 'addEventListener', 'addListener']);
434432

435-
function extractCallbackDefinition(callNode) {
436-
const fn = callNode.childForFieldName('function');
433+
function extractCallbackDefinition(callNode, fn) {
434+
if (!fn) fn = callNode.childForFieldName('function');
437435
if (!fn || fn.type !== 'member_expression') return null;
438436

439437
const prop = fn.childForFieldName('property');

0 commit comments

Comments
 (0)