From 96cfe82664c07163930444e835437ea0c44e5332 Mon Sep 17 00:00:00 2001 From: Matt Mastracci Date: Tue, 27 Feb 2024 20:30:17 -0700 Subject: perf(cli): reduce overhead in test registration (#22552) - Removes the origin call, since all origins are the same for an isolate (ie: the main module) - Collects the `TestDescription`s and sends them all at the same time inside of an Arc, allowing us to (later on) re-use these instead of cloning. Needs a follow-up pass to remove all the cloning, but that's a thread that is pretty long to pull --------- Signed-off-by: Matt Mastracci --- cli/js/40_test.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'cli/js/40_test.js') diff --git a/cli/js/40_test.js b/cli/js/40_test.js index dc14c7914..2e448e847 100644 --- a/cli/js/40_test.js +++ b/cli/js/40_test.js @@ -11,6 +11,7 @@ const { op_test_event_step_result_ignored, op_test_event_step_result_ok, op_test_event_step_wait, + op_test_get_origin, } = core.ops; const { ArrayPrototypeFilter, @@ -188,6 +189,9 @@ function wrapInner(fn) { const registerTestIdRetBuf = new Uint32Array(1); const registerTestIdRetBufU8 = new Uint8Array(registerTestIdRetBuf.buffer); +// As long as we're using one isolate per test, we can cache the origin since it won't change +let cachedOrigin = undefined; + function testInner( nameOrFnOrOptions, optionsOrFn, @@ -279,11 +283,15 @@ function testInner( // Delete this prop in case the user passed it. It's used to detect steps. delete testDesc.parent; + if (cachedOrigin == undefined) { + cachedOrigin = op_test_get_origin(); + } + testDesc.location = core.currentUserCallSite(); testDesc.fn = wrapTest(testDesc); testDesc.name = escapeName(testDesc.name); - const origin = op_register_test( + op_register_test( testDesc.fn, testDesc.name, testDesc.ignore, @@ -296,7 +304,7 @@ function testInner( registerTestIdRetBufU8, ); testDesc.id = registerTestIdRetBuf[0]; - testDesc.origin = origin; + testDesc.origin = cachedOrigin; MapPrototypeSet(testStates, testDesc.id, { context: createTestContext(testDesc), children: [], -- cgit v1.2.3