only call Instant:now once in send_on_path
Currently Instant::now is called twice, and is
surprisingly visible on flamegraphs.
diff --git a/quiche/src/lib.rs b/quiche/src/lib.rs
index 148bac7..b3cd7f0 100644
--- a/quiche/src/lib.rs
+++ b/quiche/src/lib.rs
@@ -3127,8 +3127,10 @@
return Err(Error::Done);
}
+ let now = time::Instant::now();
+
if self.local_error.is_none() {
- self.do_handshake(time::Instant::now())?;
+ self.do_handshake(now)?;
}
// Forwarding the error value here could confuse
@@ -3176,6 +3178,7 @@
&mut out[done..done + left],
send_pid,
has_initial,
+ now,
) {
Ok(v) => v,
@@ -3243,9 +3246,8 @@
fn send_single(
&mut self, out: &mut [u8], send_pid: usize, has_initial: bool,
+ now: time::Instant,
) -> Result<(packet::Type, usize)> {
- let now = time::Instant::now();
-
if out.is_empty() {
return Err(Error::BufferTooShort);
}
@@ -13193,7 +13195,7 @@
pipe.client.paths.get_active_path_id().expect("no active");
let (ty, len) = pipe
.client
- .send_single(&mut buf, active_pid, false)
+ .send_single(&mut buf, active_pid, false, time::Instant::now())
.unwrap();
assert_eq!(ty, Type::Initial);
@@ -13202,7 +13204,7 @@
// Client sends Handshake packet.
let (ty, len) = pipe
.client
- .send_single(&mut buf, active_pid, false)
+ .send_single(&mut buf, active_pid, false, time::Instant::now())
.unwrap();
assert_eq!(ty, Type::Handshake);