diff --git a/aquatic/src/lib/common.rs b/aquatic/src/lib/common.rs index 8ffbd7f..d21d711 100644 --- a/aquatic/src/lib/common.rs +++ b/aquatic/src/lib/common.rs @@ -36,6 +36,7 @@ impl PeerStatus { /// Determine peer status from announce event and number of bytes left. /// /// Likely, the last branch will be taken most of the time. + #[inline] pub fn from_event_and_bytes_left( event: AnnounceEvent, bytes_left: NumberOfBytes @@ -62,12 +63,14 @@ pub struct Peer { impl Peer { + #[inline(always)] pub fn to_response_peer(&self) -> ResponsePeer { ResponsePeer { ip_address: self.ip_address, port: self.port } } + #[inline] pub fn from_announce_and_ip( announce_request: &AnnounceRequest, ip_address: IpAddr diff --git a/aquatic/src/lib/handlers.rs b/aquatic/src/lib/handlers.rs index 9f391a7..4317d46 100644 --- a/aquatic/src/lib/handlers.rs +++ b/aquatic/src/lib/handlers.rs @@ -214,6 +214,7 @@ pub fn extract_response_peers( } +#[inline(always)] pub fn create_torrent_scrape_statistics( seeders: i32, leechers: i32 diff --git a/aquatic_bench/src/bin/bench_handlers/main.rs b/aquatic_bench/src/bin/bench_handlers/main.rs index 4a6e6f0..78b8115 100644 --- a/aquatic_bench/src/bin/bench_handlers/main.rs +++ b/aquatic_bench/src/bin/bench_handlers/main.rs @@ -4,9 +4,9 @@ //! ``` //! ## Average results over 50 rounds //! -//! Connect handler: 2 514 978 requests/second, 397.87 ns/request -//! Announce handler: 246 744 requests/second, 4054.58 ns/request -//! Scrape handler: 499 385 requests/second, 2007.23 ns/request +//! Connect handler: 2 519 969 requests/second, 397.36 ns/request +//! Announce handler: 270 880 requests/second, 3691.91 ns/request +//! Scrape handler: 510 028 requests/second, 1961.18 ns/request //! ``` use std::time::{Duration, Instant}; diff --git a/bittorrent_udp/src/converters/common.rs b/bittorrent_udp/src/converters/common.rs index 8ae18d4..3feb82a 100644 --- a/bittorrent_udp/src/converters/common.rs +++ b/bittorrent_udp/src/converters/common.rs @@ -1,6 +1,7 @@ use crate::types; +#[inline] pub fn event_from_i32(i: i32) -> types::AnnounceEvent { match i { 1 => types::AnnounceEvent::Completed, @@ -11,6 +12,7 @@ pub fn event_from_i32(i: i32) -> types::AnnounceEvent { } +#[inline] pub fn event_to_i32(event: types::AnnounceEvent) -> i32 { match event { types::AnnounceEvent::None => 0, diff --git a/bittorrent_udp/src/converters/requests.rs b/bittorrent_udp/src/converters/requests.rs index 1d80bd6..4157330 100644 --- a/bittorrent_udp/src/converters/requests.rs +++ b/bittorrent_udp/src/converters/requests.rs @@ -12,6 +12,7 @@ use super::common::*; const MAGIC_NUMBER: i64 = 4_497_486_125_440; +#[inline] pub fn request_to_bytes( bytes: &mut impl Write, request: types::Request @@ -60,6 +61,7 @@ pub fn request_to_bytes( } +#[inline] pub fn request_from_bytes( bytes: &[u8], max_scrape_torrents: u8, @@ -110,9 +112,8 @@ pub fn request_from_bytes( let opt_ip = if ip == [0; 4] { None - } - else { - Some(Ipv4Addr::new(ip[0], ip[1], ip[2], ip[3])) + } else { + Some(Ipv4Addr::from(ip)) }; Ok(types::Request::Announce(types::AnnounceRequest { diff --git a/bittorrent_udp/src/converters/responses.rs b/bittorrent_udp/src/converters/responses.rs index 65f22ec..1954097 100644 --- a/bittorrent_udp/src/converters/responses.rs +++ b/bittorrent_udp/src/converters/responses.rs @@ -7,6 +7,7 @@ use std::net::{IpAddr, Ipv6Addr, Ipv4Addr}; use crate::types; +#[inline] pub fn response_to_bytes( bytes: &mut impl Write, response: types::Response, @@ -78,6 +79,7 @@ pub fn response_to_bytes( } +#[inline] pub fn response_from_bytes( bytes: &[u8], ip_version: types::IpVersion,