Skip to content

Commit 54f9464

Browse files
committed
test(napi/parser): add benchmarks for lazy visit alone (#11866)
Add benchmarks for lazy visitor in isolation (i.e. without also parsing).
1 parent 6c5ee78 commit 54f9464

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

napi/parser/bench.bench.mjs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ const require = createRequire(import.meta.filename);
1111
const deserializeJS = require('./generated/deserialize/js.js');
1212
const deserializeTS = require('./generated/deserialize/ts.js');
1313
const { isJsAst, prepareRaw, returnBufferToCache } = require('./raw-transfer/common.js');
14+
const { getVisitorsArr } = require('./raw-transfer/visitor.js');
15+
const { TOKEN } = require('./raw-transfer/lazy-common.js');
16+
const walkProgram = require('./generated/deserialize/lazy-visit.js');
1417

1518
// Same fixtures as used in Rust parser benchmarks
1619
let fixtureUrls = [
@@ -164,5 +167,33 @@ for (const { filename, code } of fixtures) {
164167
visit(identVisitor);
165168
dispose();
166169
});
170+
171+
const debuggerVisitorsArr = getVisitorsArr(debuggerVisitor);
172+
const identVisitorsArr = getVisitorsArr(identVisitor);
173+
174+
const ast = {
175+
buffer,
176+
sourceText: code,
177+
sourceLen: sourceByteLen,
178+
sourceIsAscii: code.length === sourceByteLen,
179+
nodes: null, // Initialized in bench functions
180+
token: TOKEN,
181+
};
182+
183+
// (2 * 1024 * 1024 * 1024 - 16) >> 2
184+
const metadataPos32 = 536870908;
185+
const programPos = buffer.uint32[metadataPos32];
186+
187+
benchRaw('parser_napi_raw_lazy_visit_only(debugger)', () => {
188+
ast.nodes = new Map();
189+
debuggerCount = 0;
190+
walkProgram(programPos, ast, debuggerVisitorsArr);
191+
});
192+
193+
benchRaw('parser_napi_raw_lazy_visit_only(ident)', () => {
194+
ast.nodes = new Map();
195+
identCount = 0;
196+
walkProgram(programPos, ast, identVisitorsArr);
197+
});
167198
});
168199
}

0 commit comments

Comments
 (0)