Skip to content

Commit ad5cf87

Browse files
authored
perf: Replace hash usage with gxhash (#1028)
* perf: Replace hash usage with gxhash * Update ci.yml * Update cloudbuild.yaml * Update Dockerfile
1 parent 1d6b455 commit ad5cf87

File tree

12 files changed

+41
-35
lines changed

12 files changed

+41
-35
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ concurrency:
2929
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
3030
cancel-in-progress: true
3131

32+
env:
33+
CARGO_TERM_COLOR: always
34+
RUSTFLAGS: "-C target-feature=+aes,+vaes,+avx2"
35+
3236
jobs:
3337
lint:
3438
name: Lint

Cargo.lock

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ strum_macros = "0.26"
149149
cfg-if = "1.0.0"
150150
libflate = "2.0.0"
151151
form_urlencoded = "1.2.1"
152+
gxhash = "3.4.1"
152153

153154
[dependencies.hyper-util]
154155
version = "0.1"
@@ -236,4 +237,4 @@ schemars = { version = "0.8.15", features = ["bytes", "url"] }
236237
url = { version = "2.4.1", features = ["serde"] }
237238

238239
[workspace.lints.clippy]
239-
undocumented_unsafe_blocks = "deny"
240+
undocumented_unsafe_blocks = "deny"

build/build-image/Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ ARG RUST_TOOLCHAIN
1919
ENV RUSTUP_HOME=/usr/local/rustup \
2020
CARGO_HOME=/usr/local/cargo \
2121
PATH=/usr/local/cargo/bin:$PATH \
22+
CARGO_TERM_COLOR=always \
23+
RUSTFLAGS="-C target-feature=+aes,+vaes,+avx2" \
2224
LC_ALL=C.UTF-8 \
2325
LANG=C.UTF-8
2426

cloudbuild.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ options:
103103
- "CARGO_HOME=/workspace/.cargo"
104104
- "REPOSITORY=${_REPOSITORY}"
105105
- "BUILD_IMAGE_TAG=${_BUILD_IMAGE_TAG}"
106+
- "CARGO_TERM_COLOR=always"
107+
- 'RUSTFLAGS="-C target-feature=+aes,+vaes,+avx2"'
106108
machineType: E2_HIGHCPU_32
107109
dynamic_substitutions: true
108110
timeout: 7200s

src/components/proxy/error.rs

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -105,17 +105,7 @@ impl Hash for PipelineError {
105105
}
106106
}
107107

108-
pub struct SeahashBuilder;
109-
110-
impl std::hash::BuildHasher for SeahashBuilder {
111-
type Hasher = seahash::SeaHasher;
112-
113-
fn build_hasher(&self) -> Self::Hasher {
114-
seahash::SeaHasher::new()
115-
}
116-
}
117-
118-
pub type ErrorMap = std::collections::HashMap<PipelineError, u64, SeahashBuilder>;
108+
pub type ErrorMap = gxhash::HashMap<PipelineError, u64>;
119109

120110
pub type ErrorSender = tokio::sync::mpsc::Sender<ErrorMap>;
121111
//pub type ErrorReceiver = tokio::sync::mpsc::Receiver<ErrorMap>;
@@ -140,7 +130,7 @@ pub struct ErrorAccumulator {
140130
impl ErrorAccumulator {
141131
pub fn new(tx: ErrorSender) -> Self {
142132
Self {
143-
map: ErrorMap::with_hasher(SeahashBuilder),
133+
map: <_>::default(),
144134
tx,
145135
oldest: Instant::now(),
146136
}
@@ -160,7 +150,7 @@ impl ErrorAccumulator {
160150
};
161151

162152
#[allow(clippy::mutable_key_type)]
163-
let map = std::mem::replace(&mut self.map, ErrorMap::with_hasher(SeahashBuilder));
153+
let map = std::mem::take(&mut self.map);
164154
permit.send(map);
165155
true
166156
}

src/components/proxy/packet_router.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ pub async fn spawn_receivers(
169169
let mut log_task = tokio::time::interval(std::time::Duration::from_secs(5));
170170

171171
#[allow(clippy::mutable_key_type)]
172-
let mut pipeline_errors = super::error::ErrorMap::with_hasher(super::error::SeahashBuilder);
172+
let mut pipeline_errors = super::error::ErrorMap::default();
173173

174174
#[allow(clippy::mutable_key_type)]
175175
fn report(errors: &mut super::error::ErrorMap) {

src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ impl Config {
234234
crate::net::cluster::proto::FilterChain::try_from(&*self.filters.load())?,
235235
);
236236
let any = resource.try_encode()?;
237-
let version = seahash::hash(&any.value);
237+
let version = gxhash::gxhash64(&any.value, 0xdeadbeef);
238238

239239
let vstr = version.to_string();
240240

src/filters/read.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ impl ReadContext {
5050
destinations: Vec::new(),
5151
source,
5252
contents,
53-
metadata: DynamicMetadata::new(),
53+
metadata: <_>::default(),
5454
}
5555
}
5656
}

src/filters/write.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
* limitations under the License.
1515
*/
1616

17-
use std::collections::HashMap;
18-
1917
use crate::{
2018
net::endpoint::{DynamicMetadata, EndpointAddress},
2119
pool::PoolBuffer,
@@ -45,7 +43,7 @@ impl WriteContext {
4543
source,
4644
dest,
4745
contents,
48-
metadata: HashMap::new(),
46+
metadata: <_>::default(),
4947
}
5048
}
5149
}

0 commit comments

Comments
 (0)