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/ops/testing.rs | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) (limited to 'cli/ops/testing.rs') diff --git a/cli/ops/testing.rs b/cli/ops/testing.rs index 8e7a5bb03..eb7cf71ce 100644 --- a/cli/ops/testing.rs +++ b/cli/ops/testing.rs @@ -1,5 +1,6 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +use crate::tools::test::TestContainer; use crate::tools::test::TestDescription; use crate::tools::test::TestEvent; use crate::tools::test::TestEventSender; @@ -23,17 +24,13 @@ use std::sync::atomic::AtomicUsize; use std::sync::atomic::Ordering; use uuid::Uuid; -#[derive(Default)] -pub(crate) struct TestContainer( - pub Vec<(TestDescription, v8::Global)>, -); - deno_core::extension!(deno_test, ops = [ op_pledge_test_permissions, op_restore_test_permissions, op_register_test, op_register_test_step, + op_test_get_origin, op_test_event_step_wait, op_test_event_step_result_ok, op_test_event_step_result_ignored, @@ -106,7 +103,6 @@ static NEXT_ID: AtomicUsize = AtomicUsize::new(0); #[allow(clippy::too_many_arguments)] #[op2] -#[string] fn op_register_test( state: &mut OpState, #[global] function: v8::Global, @@ -119,7 +115,7 @@ fn op_register_test( #[smi] line_number: u32, #[smi] column_number: u32, #[buffer] ret_buf: &mut [u8], -) -> Result { +) -> Result<(), AnyError> { if ret_buf.len() != 4 { return Err(type_error(format!( "Invalid ret_buf length: {}", @@ -142,14 +138,16 @@ fn op_register_test( column_number, }, }; - state - .borrow_mut::() - .0 - .push((description.clone(), function)); - let sender = state.borrow_mut::(); - sender.send(TestEvent::Register(description)).ok(); + let container = state.borrow_mut::(); + container.register(description, function); ret_buf.copy_from_slice(&(id as u32).to_le_bytes()); - Ok(origin) + Ok(()) +} + +#[op2] +#[string] +fn op_test_get_origin(state: &mut OpState) -> String { + state.borrow::().to_string() } #[op2(fast)] -- cgit v1.2.3