Skip to content

Commit cde2816

Browse files
olix0rhawkw
andauthored
Remove unneeded uses of indexmap (#1048)
We initially adopted `indexmap` in many places where it's not strictly necessary: we don't actually rely on the data being insert-ordered and don't need to mutate the structure while iterating over it. In fact, the traffic split module is the only place in the codebase where we access the data structure by index (rather than by key). In all other cases, we do not care about insertion-order. In the vast majority of cases we can simply use a `HashMap`. Endpoint and route labels need to be reliably ordered so that they can be compared (i.e. implementing `Eq`), in which case the standard `BTreeMap` works sufficiently. This change eliminates unnecessary uses of `indexmap` to reduce dependency and conceptual overhead. Co-authored-by: Eliza Weisman <[email protected]>
1 parent 7066e7d commit cde2816

File tree

32 files changed

+112
-137
lines changed

32 files changed

+112
-137
lines changed

Cargo.lock

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,6 @@ name = "linkerd-app"
618618
version = "0.1.0"
619619
dependencies = [
620620
"futures",
621-
"indexmap",
622621
"ipnet",
623622
"linkerd-app-admin",
624623
"linkerd-app-core",
@@ -663,7 +662,6 @@ dependencies = [
663662
"http",
664663
"http-body",
665664
"hyper",
666-
"indexmap",
667665
"ipnet",
668666
"linkerd-addr",
669667
"linkerd-cache",
@@ -723,7 +721,6 @@ version = "0.1.0"
723721
dependencies = [
724722
"futures",
725723
"http",
726-
"indexmap",
727724
"linkerd-app-core",
728725
"linkerd-app-inbound",
729726
"linkerd-app-outbound",
@@ -745,7 +742,6 @@ dependencies = [
745742
"futures",
746743
"http",
747744
"hyper",
748-
"indexmap",
749745
"libfuzzer-sys",
750746
"linkerd-app-core",
751747
"linkerd-app-test",
@@ -796,7 +792,6 @@ dependencies = [
796792
"futures",
797793
"http",
798794
"hyper",
799-
"indexmap",
800795
"ipnet",
801796
"linkerd-app-core",
802797
"linkerd-app-test",
@@ -931,7 +926,6 @@ name = "linkerd-error-metrics"
931926
version = "0.1.0"
932927
dependencies = [
933928
"futures",
934-
"indexmap",
935929
"linkerd-metrics",
936930
"pin-project",
937931
"tower",
@@ -992,7 +986,6 @@ dependencies = [
992986
"http",
993987
"http-body",
994988
"hyper",
995-
"indexmap",
996989
"linkerd-error",
997990
"linkerd-http-classify",
998991
"linkerd-metrics",
@@ -1056,7 +1049,6 @@ dependencies = [
10561049
"hdrhistogram",
10571050
"http",
10581051
"hyper",
1059-
"indexmap",
10601052
"parking_lot",
10611053
"quickcheck",
10621054
"tokio",
@@ -1088,7 +1080,6 @@ dependencies = [
10881080
"futures",
10891081
"http",
10901082
"http-body",
1091-
"indexmap",
10921083
"linkerd-addr",
10931084
"linkerd-error",
10941085
"linkerd-proxy-core",
@@ -1158,7 +1149,6 @@ dependencies = [
11581149
"httparse",
11591150
"hyper",
11601151
"hyper-balance",
1161-
"indexmap",
11621152
"linkerd-detect",
11631153
"linkerd-duplex",
11641154
"linkerd-error",
@@ -1216,7 +1206,6 @@ dependencies = [
12161206
"futures",
12171207
"http",
12181208
"hyper",
1219-
"indexmap",
12201209
"ipnet",
12211210
"linkerd-conditional",
12221211
"linkerd-error",
@@ -1357,7 +1346,6 @@ dependencies = [
13571346
name = "linkerd-stack-metrics"
13581347
version = "0.1.0"
13591348
dependencies = [
1360-
"indexmap",
13611349
"linkerd-metrics",
13621350
"tokio",
13631351
"tower",

linkerd/app/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ allow-loopback = ["linkerd-app-outbound/allow-loopback"]
1616

1717
[dependencies]
1818
futures = { version = "0.3", default-features = false }
19-
indexmap = "1.6"
2019
ipnet = "2.3"
2120
linkerd-app-admin = { path = "./admin" }
2221
linkerd-app-core = { path = "./core" }

linkerd/app/core/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ http = "0.2"
1919
http-body = "0.4"
2020
hyper = { version = "0.14.2", features = ["http1", "http2"] }
2121
futures = { version = "0.3", default-features = false }
22-
indexmap = "1.6"
2322
ipnet = "2.3"
2423
linkerd-addr = { path = "../../addr" }
2524
linkerd-cache = { path = "../../cache" }

linkerd/app/gateway/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ publish = false
99
[dependencies]
1010
http = "0.2"
1111
futures = { version = "0.3", default-features = false }
12-
indexmap = "1.6"
1312
linkerd-app-core = { path = "../core" }
1413
linkerd-app-inbound = { path = "../inbound" }
1514
linkerd-app-outbound = { path = "../outbound" }

linkerd/app/inbound/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ Configures and runs the inbound proxy
1313
bytes = "1"
1414
http = "0.2"
1515
futures = { version = "0.3", default-features = false }
16-
indexmap = "1.6"
1716
linkerd-app-core = { path = "../core" }
1817
thiserror = "1.0"
1918
tokio = { version = "1", features = ["sync"] }

linkerd/app/inbound/src/require_identity.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
use crate::target::TcpAccept;
2-
use indexmap::IndexSet;
32
use linkerd_app_core::{svc::stack::Predicate, tls, Conditional, Error};
4-
use std::sync::Arc;
3+
use std::{collections::HashSet, sync::Arc};
54
use thiserror::Error;
65

76
/// A connection policy that fails connections that don't have a client identity
87
/// if they target one of the configured local ports.
98
#[derive(Clone, Debug)]
109
pub struct RequireIdentityForPorts {
11-
ports: Arc<IndexSet<u16>>,
10+
ports: Arc<HashSet<u16>>,
1211
}
1312

1413
#[derive(Debug, Error)]

linkerd/app/inbound/src/target.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use indexmap::IndexMap;
21
use linkerd_app_core::{
32
classify, dst, http_request_authority_addr, http_request_host_addr, identity, metrics,
43
profiles,
@@ -279,15 +278,15 @@ impl tap::Inspect for Target {
279278
Some(self.target_addr)
280279
}
281280

282-
fn dst_labels<B>(&self, _: &http::Request<B>) -> Option<&IndexMap<String, String>> {
281+
fn dst_labels<B>(&self, _: &http::Request<B>) -> Option<&tap::Labels> {
283282
None
284283
}
285284

286285
fn dst_tls<B>(&self, _: &http::Request<B>) -> tls::ConditionalClientTls {
287286
Conditional::None(tls::NoClientTls::Loopback)
288287
}
289288

290-
fn route_labels<B>(&self, req: &http::Request<B>) -> Option<Arc<IndexMap<String, String>>> {
289+
fn route_labels<B>(&self, req: &http::Request<B>) -> Option<Arc<tap::Labels>> {
291290
req.extensions()
292291
.get::<dst::Route>()
293292
.map(|r| r.route.labels().clone())

linkerd/app/outbound/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ test-subscriber = []
1818
bytes = "1"
1919
http = "0.2"
2020
futures = { version = "0.3", default-features = false }
21-
indexmap = "1.6"
2221
linkerd-app-core = { path = "../core" }
2322
linkerd-http-retry = { path = "../../http-retry" }
2423
linkerd-identity = { path = "../../identity" }

linkerd/app/outbound/src/http/endpoint.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ mod test {
182182
opaque_protocol: false,
183183
tls: tls::ConditionalClientTls::None(tls::NoClientTls::Disabled),
184184
metadata: Metadata::new(
185-
Default::default(),
185+
None,
186186
support::resolver::ProtocolHint::Http2,
187187
None,
188188
None,
@@ -230,7 +230,7 @@ mod test {
230230
opaque_protocol: false,
231231
tls: tls::ConditionalClientTls::None(tls::NoClientTls::Disabled),
232232
metadata: Metadata::new(
233-
Default::default(),
233+
None,
234234
support::resolver::ProtocolHint::Http2,
235235
None,
236236
None,

linkerd/app/outbound/src/http/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ mod require_id_header;
55
mod server;
66

77
use crate::tcp;
8-
use indexmap::IndexMap;
98
pub use linkerd_app_core::proxy::http::*;
109
use linkerd_app_core::{
1110
dst,
@@ -173,15 +172,15 @@ impl tap::Inspect for Endpoint {
173172
Some(self.addr.into())
174173
}
175174

176-
fn dst_labels<B>(&self, _: &Request<B>) -> Option<&IndexMap<String, String>> {
175+
fn dst_labels<B>(&self, _: &Request<B>) -> Option<&tap::Labels> {
177176
Some(self.metadata.labels())
178177
}
179178

180179
fn dst_tls<B>(&self, _: &Request<B>) -> tls::ConditionalClientTls {
181180
self.tls.clone()
182181
}
183182

184-
fn route_labels<B>(&self, req: &Request<B>) -> Option<Arc<IndexMap<String, String>>> {
183+
fn route_labels<B>(&self, req: &Request<B>) -> Option<Arc<tap::Labels>> {
185184
req.extensions()
186185
.get::<dst::Route>()
187186
.map(|r| r.route.labels().clone())

0 commit comments

Comments
 (0)