diff --git a/stdlib/src/async_mod.rs b/stdlib/src/async_mod.rs index 77ad5b61..0f3f6dd5 100644 --- a/stdlib/src/async_mod.rs +++ b/stdlib/src/async_mod.rs @@ -17,7 +17,8 @@ impl StdlibRegistry { arity: 1, callback: |_ctx, args| { let callback = args[0].clone(); - let mut fut_map = IndexMap::new(); + // ⚡ Bolt Performance Optimization: Pre-allocated IndexMap capacity to avoid re-hashing during insertion. + let mut fut_map = IndexMap::with_capacity(2); fut_map.insert( "state".to_string(), RuntimeValue::Str("pending".to_string()), @@ -68,7 +69,8 @@ impl StdlibRegistry { name: "make_future".to_string(), arity: 0, callback: |_ctx, _args| { - let mut fut_map = IndexMap::new(); + // ⚡ Bolt Performance Optimization: Pre-allocated IndexMap capacity to avoid re-hashing during insertion. + let mut fut_map = IndexMap::with_capacity(2); fut_map.insert( "state".to_string(), RuntimeValue::Str("pending".to_string()), @@ -106,7 +108,8 @@ impl StdlibRegistry { let (tx, rx) = std::sync::mpsc::channel::(); let tx_id = ctx.resources.borrow_mut().insert(tx); let rx_id = ctx.resources.borrow_mut().insert(rx); - let mut map = IndexMap::new(); + // ⚡ Bolt Performance Optimization: Pre-allocated IndexMap capacity to avoid re-hashing during insertion. + let mut map = IndexMap::with_capacity(2); map.insert("_tx_handle".to_string(), RuntimeValue::Int(tx_id as i64)); map.insert("_rx_handle".to_string(), RuntimeValue::Int(rx_id as i64)); Ok(RuntimeValue::Map { diff --git a/stdlib/src/net_handler.rs b/stdlib/src/net_handler.rs index 4c3e45d2..fbaa9084 100644 --- a/stdlib/src/net_handler.rs +++ b/stdlib/src/net_handler.rs @@ -20,7 +20,8 @@ pub fn tcp_listen_fn( ) })?; let handle_id = ctx.resources.borrow_mut().insert(listener); - let mut listener_map = IndexMap::new(); + // ⚡ Bolt Performance Optimization: Pre-allocated IndexMap capacity to avoid re-hashing during insertion. + let mut listener_map = IndexMap::with_capacity(2); listener_map.insert("port".to_string(), RuntimeValue::Int(port)); listener_map.insert("_handle".to_string(), RuntimeValue::Int(handle_id as i64)); Ok(RuntimeValue::Map { @@ -43,7 +44,8 @@ pub fn tcp_connect_fn( ) })?; let handle_id = ctx.resources.borrow_mut().insert(stream); - let mut stream_map = IndexMap::new(); + // ⚡ Bolt Performance Optimization: Pre-allocated IndexMap capacity to avoid re-hashing during insertion. + let mut stream_map = IndexMap::with_capacity(3); stream_map.insert("ip".to_string(), RuntimeValue::Str(ip)); stream_map.insert("port".to_string(), RuntimeValue::Int(port)); stream_map.insert("_handle".to_string(), RuntimeValue::Int(handle_id as i64)); diff --git a/stdlib/src/process.rs b/stdlib/src/process.rs index f050f5e8..590d8a8c 100644 --- a/stdlib/src/process.rs +++ b/stdlib/src/process.rs @@ -62,7 +62,8 @@ fn process_run( ) })?; - let mut res_map = IndexMap::new(); + // ⚡ Bolt Performance Optimization: Pre-allocated IndexMap capacity to avoid re-hashing during insertion. + let mut res_map = IndexMap::with_capacity(3); res_map.insert( "stdout".to_string(), RuntimeValue::Str(String::from_utf8_lossy(&output.stdout).to_string()),