summaryrefslogtreecommitdiff
path: root/cli/js
diff options
context:
space:
mode:
authorMatt Mastracci <matthew@mastracci.com>2024-02-27 20:30:17 -0700
committerGitHub <noreply@github.com>2024-02-27 20:30:17 -0700
commit96cfe82664c07163930444e835437ea0c44e5332 (patch)
tree896f92b8bf4e569cf37adabf03e5a75ce8dbff58 /cli/js
parent9b5d2f8c1bae498d78400c8e9263bcae6e521adf (diff)
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 <matthew@mastracci.com>
Diffstat (limited to 'cli/js')
-rw-r--r--cli/js/40_test.js12
1 files changed, 10 insertions, 2 deletions
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: [],