Skip to content

Commit 33c6c5e

Browse files
authored
Optimize dependencies (#1219)
1 parent 904f479 commit 33c6c5e

10 files changed

Lines changed: 164 additions & 102 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@ src/protos/*.rs
2323
/.cloud_certs/
2424
cloud_envs.fish
2525
/.claude/settings.local.json
26+
.codex

Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ license = "MIT"
1414
license-file = "LICENSE.txt"
1515

1616
[workspace.dependencies]
17-
bon = { version = "3", features = ["implied-bounds"] }
18-
derive_more = { version = "2.0", features = [
17+
bon = { version = "3", default-features = false, features = ["alloc", "implied-bounds"] }
18+
derive_more = { version = "2.0", default-features = false, features = [
1919
"constructor",
2020
"display",
2121
"from",
@@ -24,10 +24,10 @@ derive_more = { version = "2.0", features = [
2424
"try_into",
2525
] }
2626
thiserror = "2"
27-
tonic = "0.14"
27+
tonic = { version = "0.14", default-features = false }
2828
tonic-prost = "0.14"
2929
tonic-prost-build = "0.14"
30-
opentelemetry = { version = "0.31", features = ["metrics"] }
30+
opentelemetry = { version = "0.31", default-features = false, features = ["metrics"] }
3131
prost = "0.14"
3232
prost-types = { version = "0.7", package = "prost-wkt-types" }
3333
pbjson = "0.9"

crates/client/Cargo.toml

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ anyhow = "1.0"
2222
async-trait = "0.1"
2323
backoff = "0.4"
2424
base64 = "0.22"
25-
bon = "3"
25+
bon = { version = "3", default-features = false, features = ["alloc"] }
2626
derive_more = { workspace = true }
2727
dyn-clone = "1.0"
2828
bytes = "1.10"
@@ -35,12 +35,18 @@ hyper-util = "0.1.16"
3535
opentelemetry = { workspace = true, features = ["metrics"], optional = true }
3636
parking_lot = "0.12"
3737
thiserror = { workspace = true }
38-
tokio = { version = "1.47", features = ["net", "time"] }
39-
tonic = { workspace = true, features = ["tls-ring", "tls-native-roots"] }
38+
tokio = { version = "1.47", default-features = false, features = [
39+
"io-util",
40+
"net",
41+
"rt",
42+
"sync",
43+
"time",
44+
] }
45+
tonic = { workspace = true, default-features = false, features = ["tls-ring", "tls-native-roots", "channel"] }
4046
tower = { version = "0.5", features = ["util"] }
4147
tracing = "0.1"
4248
url = "2.5"
43-
uuid = { version = "1.18", features = ["v4"] }
49+
uuid = { version = "1.18", default-features = false, features = ["v4"] }
4450
rand = "0.10"
4551

4652
[dependencies.temporalio-common]
@@ -54,6 +60,14 @@ prost = "0.14"
5460
prost-types = { workspace = true }
5561
rstest = "0.26"
5662
tempfile = "3"
63+
tokio = { version = "1.47", default-features = false, features = [
64+
"io-util",
65+
"macros",
66+
"net",
67+
"rt",
68+
"sync",
69+
"time",
70+
] }
5771

5872
[lints]
5973
workspace = true

crates/common/Cargo.toml

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ crc32fast = "1"
4242
dirs = { version = "6.0", optional = true }
4343
derive_more = { workspace = true }
4444
erased-serde = "0.4"
45-
futures = "0.3"
45+
futures = { version = "0.3", default-features = false, features = ["alloc"] }
4646
futures-channel = { version = "0.3", default-features = false, features = [
4747
"std",
4848
], optional = true }
@@ -55,17 +55,18 @@ hyper-util = { version = "0.1", features = [
5555
"tokio",
5656
], optional = true }
5757
opentelemetry = { workspace = true, features = ["metrics"], optional = true }
58-
opentelemetry_sdk = { version = "0.31", features = [
58+
opentelemetry_sdk = { version = "0.31", default-features = false, features = [
5959
"rt-tokio",
6060
"metrics",
6161
"spec_unstable_metrics_views",
6262
], optional = true }
63-
opentelemetry-otlp = { version = "0.31", features = [
63+
opentelemetry-otlp = { version = "0.31", default-features = false, features = [
6464
"tokio",
6565
"metrics",
66-
"tls",
66+
"tls-roots",
6767
"http-proto",
6868
"grpc-tonic",
69+
"reqwest-rustls",
6970
], optional = true }
7071
parking_lot = { version = "0.12" }
7172
prometheus = { version = "0.14", optional = true, default-features = false }
@@ -77,9 +78,13 @@ ringbuf = { version = "0.4", optional = true }
7778
serde = { version = "1.0", features = ["derive"] }
7879
serde_json = { workspace = true }
7980
thiserror = { workspace = true }
80-
tokio = { version = "1.47", features = [], optional = true }
81+
tokio = { version = "1.47", default-features = false, features = [
82+
"io-util",
83+
"net",
84+
"rt",
85+
], optional = true }
8186
toml = { version = "1.0", optional = true }
82-
tonic = { workspace = true }
87+
tonic = { workspace = true, default-features = false, features = ["transport", "codegen"] }
8388
tonic-prost = { workspace = true }
8489
tracing = "0.1"
8590
# TODO [rust-sdk-branch]: Is it reasonable to make this optional?
@@ -91,7 +96,7 @@ tracing-subscriber = { version = "0.3", default-features = false, features = [
9196
] }
9297
tracing-core = "0.1"
9398
url = "2.5"
94-
uuid = { version = "1.18", features = ["v4"] }
99+
uuid = { version = "1.18", default-features = false, features = ["v4"] }
95100
pbjson = { workspace = true }
96101

97102
[build-dependencies]

crates/sdk-core-c-bridge/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ rand = "0.10"
3030
rand_pcg = "0.10"
3131
serde = { version = "1.0", features = ["derive"] }
3232
serde_json = { workspace = true }
33-
tokio = "1.47"
34-
tokio-stream = "0.1"
33+
tokio = { version = "1.47", default-features = false, features = ["sync"] }
34+
tokio-stream = { version = "0.1", default-features = false }
3535
tokio-util = "0.7"
36-
tonic = { workspace = true }
36+
tonic = { workspace = true, default-features = false }
3737
tracing = "0.1"
3838
url = "2.5"
3939
# This is only needed as an explicit dependency so we can enable static as a feature

crates/sdk-core/Cargo.toml

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,31 +39,30 @@ async-trait = "0.1"
3939
bon = { workspace = true }
4040
crossbeam-channel = "0.5"
4141
crossbeam-utils = "0.8"
42-
dashmap = "6.1"
4342
derive_more = { workspace = true }
4443
enum_dispatch = "0.3"
4544
enum-iterator = "2"
4645
flate2 = { version = "1.1", optional = true }
4746
futures = { version = "0.3", default-features = false }
4847
futures-util = { version = "0.3", default-features = false }
4948
gethostname = "1.0.2"
50-
governor = "0.10"
5149
hyper = { version = "1.7", optional = true }
5250
itertools = "0.14"
5351
lru = "0.16"
5452
mockall = "0.14"
5553
opentelemetry = { workspace = true, features = ["metrics"], optional = true }
56-
opentelemetry_sdk = { version = "0.31", features = [
54+
opentelemetry_sdk = { version = "0.31", default-features = false, features = [
5755
"rt-tokio",
5856
"metrics",
5957
"spec_unstable_metrics_views",
6058
], optional = true }
61-
opentelemetry-otlp = { version = "0.31", features = [
59+
opentelemetry-otlp = { version = "0.31", default-features = false, features = [
6260
"tokio",
6361
"metrics",
64-
"tls",
62+
"tls-roots",
6563
"http-proto",
6664
"grpc-tonic",
65+
"reqwest-rustls",
6766
], optional = true }
6867
parking_lot = { version = "0.12" }
6968
pid = "4.0"
@@ -84,20 +83,21 @@ slotmap = "1.0"
8483
sysinfo = { version = "0.38", default-features = false, features = ["system"] }
8584
tar = { version = "0.4", optional = true }
8685
thiserror = { workspace = true }
87-
tokio = { version = "1.47", features = [
86+
tokio = { version = "1.47", default-features = false, features = [
8887
"rt",
8988
"rt-multi-thread",
9089
"parking_lot",
9190
"time",
9291
"fs",
9392
"process",
93+
"macros",
9494
] }
9595
tokio-util = { version = "0.7", features = ["io", "io-util"] }
96-
tokio-stream = "0.1"
97-
tonic = { workspace = true, features = ["tls-ring", "tls-native-roots"] }
96+
tokio-stream = { version = "0.1", default-features = false }
97+
tonic = { workspace = true, default-features = false, features = ["tls-ring", "tls-native-roots", "transport", "codegen"] }
9898
tracing = "0.1"
9999
url = "2.5"
100-
uuid = { version = "1.18", features = ["v4"] }
100+
uuid = { version = "1.18", default-features = false, features = ["v4"] }
101101
# Only need specific features to decompress zip files for ephemeral server download
102102
zip = { version = "8.4", optional = true, default-features = false, features = [
103103
"deflate",
@@ -138,16 +138,18 @@ hyper-util = { version = "0.1", features = [
138138
rstest = "0.26"
139139
semver = "1.0"
140140
temporalio-sdk = { path = "../sdk" }
141-
tokio = { version = "1.47", features = [
141+
tokio = { version = "1.47", default-features = false, features = [
142142
"rt",
143143
"rt-multi-thread",
144144
"parking_lot",
145145
"time",
146146
"fs",
147147
"process",
148148
"test-util",
149+
"macros",
149150
] }
150-
tokio-stream = { version = "0.1", features = ["net"] }
151+
tokio-stream = { version = "0.1", default-features = false, features = ["net"] }
152+
tonic = { workspace = true, default-features = false, features = ["router"] }
151153
tracing-subscriber = { version = "0.3", default-features = false }
152154
trybuild = { version = "1.0", features = ["diff"] }
153155

@@ -202,6 +204,7 @@ name = "workflow_replay"
202204
path = "benches/workflow_replay_bench.rs"
203205
test = false
204206
harness = false
207+
required-features = ["test-utilities"]
205208

206209
# The integration test runner should compile with the same configuration as the
207210
# rest of the integration tests so that artifacts are shared and no additional

crates/sdk-core/src/pollers/poll_buffer.rs

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use crate::{
1010
use backoff::{SystemClock, backoff::Backoff, exponential::ExponentialBackoff};
1111
use crossbeam_utils::atomic::AtomicCell;
1212
use futures_util::{FutureExt, StreamExt, future::BoxFuture};
13-
use governor::{Quota, RateLimiter};
1413
use std::{
1514
cmp,
1615
fmt::Debug,
@@ -19,7 +18,7 @@ use std::{
1918
Arc,
2019
atomic::{AtomicBool, AtomicUsize, Ordering},
2120
},
22-
time::{Duration, SystemTime},
21+
time::{Duration, Instant, SystemTime},
2322
};
2423
use temporalio_client::{
2524
ERROR_RETURNED_DUE_TO_SHORT_CIRCUIT, request_extensions::NoRetryOnMatching,
@@ -45,6 +44,32 @@ use tracing::Instrument;
4544

4645
type PollReceiver<T, SK> =
4746
Mutex<UnboundedReceiver<pollers::Result<(T, OwnedMeteredSemPermit<SK>)>>>;
47+
48+
struct PollRateLimiter {
49+
interval: Duration,
50+
next_allowed_at: Mutex<Instant>,
51+
}
52+
53+
impl PollRateLimiter {
54+
fn new(polls_per_second: f64) -> Self {
55+
Self {
56+
interval: Duration::from_secs_f64(polls_per_second.recip()),
57+
next_allowed_at: Mutex::new(Instant::now()),
58+
}
59+
}
60+
61+
async fn wait(&self) {
62+
let scheduled_at = {
63+
let mut next_allowed_at = self.next_allowed_at.lock().await;
64+
let now = Instant::now();
65+
let scheduled_at = (*next_allowed_at).max(now);
66+
*next_allowed_at = scheduled_at + self.interval;
67+
scheduled_at
68+
};
69+
tokio::time::sleep_until(scheduled_at.into()).await;
70+
}
71+
}
72+
4873
pub(crate) struct LongPollBuffer<T, SK: SlotKind> {
4974
buffered_polls: PollReceiver<T, SK>,
5075
shutdown: CancellationToken,
@@ -163,14 +188,11 @@ impl LongPollBuffer<PollActivityTaskQueueResponse, ActivitySlotKind> {
163188
) -> Self {
164189
let pre_permit_delay = options
165190
.max_worker_acts_per_second
166-
.and_then(|ps| {
167-
Quota::with_period(Duration::from_secs_f64(ps.recip()))
168-
.map(|q| Arc::new(RateLimiter::direct(q)))
169-
})
191+
.map(|ps| Arc::new(PollRateLimiter::new(ps)))
170192
.map(|rl| {
171193
move || {
172194
let rl = rl.clone();
173-
async move { rl.until_ready().await }.boxed()
195+
async move { rl.wait().await }.boxed()
174196
}
175197
});
176198
let no_retry = if matches!(poller_behavior, PollerBehavior::Autoscaling { .. }) {

0 commit comments

Comments
 (0)