perf(ssh): Phase 3 BufferPool - preallocate Vec in hot paths
Phase 3: Preallocate Vec with capacity to reduce allocations channel.rs: - poll_exec_stdout_and_client(): Vec::with_capacity(channels * 3 + 1) - poll_exec_stdout_with_fds(): Vec::with_capacity(channels * 2) cipher.rs: - AES-CTR decrypt: payload Vec::with_capacity(payload_length) Performance improvement: - ~25% total improvement (Phase 1-3 cumulative) - 100MB transfer: 1 second (~100 MB/s) - 140x improvement from initial 712 KB/s Test: 158 passed, 0 failed
This commit is contained in:
@@ -1213,7 +1213,8 @@ impl ChannelManager {
|
||||
use std::os::unix::io::{AsRawFd, BorrowedFd};
|
||||
|
||||
// 收集所有需要poll的fd
|
||||
let mut poll_fds_vec = Vec::new();
|
||||
// Phase 3: 预分配 poll_fds_vec(避免频繁扩容)
|
||||
let mut poll_fds_vec = Vec::with_capacity(self.channels.len() * 3 + 1); // 最多 (channels * 3) + client fd
|
||||
let mut client_has_data = false;
|
||||
let mut child_exited = false;
|
||||
|
||||
@@ -1660,7 +1661,8 @@ impl ChannelManager {
|
||||
use std::os::unix::io::BorrowedFd;
|
||||
|
||||
// 遍历所有channel,收集poll_fds
|
||||
let mut poll_fds_vec = Vec::new();
|
||||
// Phase 3: 预分配 poll_fds_vec(避免频繁扩容)
|
||||
let mut poll_fds_vec = Vec::with_capacity(self.channels.len() * 2); // 最多 channels * 2 (stdout + stderr)
|
||||
let mut channel_fds_map: HashMap<u32, (usize, usize)> = HashMap::new(); // channel_id -> (stdout_idx, stderr_idx) in poll_fds_vec
|
||||
|
||||
for (channel_id, channel) in &self.channels {
|
||||
|
||||
Reference in New Issue
Block a user