-
-
Notifications
You must be signed in to change notification settings - Fork 130
perf: reduce pre-allocations, default to single-thread runtime #556
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
fd1ba33
ed06f9c
cf9875d
2671207
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -159,28 +159,28 @@ impl CacheStores { | |
| pub struct CacheConfig { | ||
| /// Group metadata cache (time_to_live). Default: 1h TTL, 250 entries. | ||
| pub group_cache: CacheEntryConfig, | ||
| /// Device registry cache (time_to_live). Default: 1h TTL, 5000 entries. | ||
| /// Device registry cache (time_to_live). Default: 1h TTL, 1000 entries. | ||
| pub device_registry_cache: CacheEntryConfig, | ||
| /// LID-to-phone cache (time_to_idle). Default: 1h timeout, 10000 entries. | ||
| /// LID-to-phone cache (time_to_idle). Default: 1h timeout, 2000 entries. | ||
| pub lid_pn_cache: CacheEntryConfig, | ||
| /// Retried group messages tracker (time_to_live). Default: 5m TTL, 2000 entries. | ||
| /// Retried group messages tracker (time_to_live). Default: 5m TTL, 500 entries. | ||
| pub retried_group_messages: CacheEntryConfig, | ||
| /// Optional L1 in-memory cache for sent messages (retry support). | ||
| /// Default: capacity 0 (disabled — DB-only, matching WA Web). | ||
| /// Set capacity > 0 to enable a fast in-memory cache in front of the DB. | ||
| pub recent_messages: CacheEntryConfig, | ||
| /// Message retry counts (time_to_live). Default: 5m TTL, 1000 entries. | ||
| /// Message retry counts (time_to_live). Default: 5m TTL, 500 entries. | ||
| pub message_retry_counts: CacheEntryConfig, | ||
| /// PDO pending requests (time_to_live). Default: 30s TTL, 500 entries. | ||
| /// PDO pending requests (time_to_live). Default: 30s TTL, 200 entries. | ||
| pub pdo_pending_requests: CacheEntryConfig, | ||
| /// Sender key device tracking cache (time_to_idle). Default: 1h TTI, 500 entries. | ||
| /// Caches per-group SKDM distribution state to avoid DB reads on every group send. | ||
| pub sender_key_devices_cache: CacheEntryConfig, | ||
|
|
||
| // --- Coordination caches (capacity-only, no TTL) --- | ||
| /// Per-device Signal session lock capacity. Default: 10000. | ||
| /// Per-device Signal session lock capacity. Default: 2000. | ||
| pub session_locks_capacity: u64, | ||
| /// Per-chat lane capacity (combined lock + queue). Default: 5000. | ||
| /// Per-chat lane capacity (combined lock + queue). Default: 1000. | ||
| pub chat_lanes_capacity: u64, | ||
|
|
||
| // --- Sent message DB cleanup --- | ||
|
|
@@ -239,18 +239,18 @@ impl Default for CacheConfig { | |
|
|
||
| Self { | ||
| group_cache: CacheEntryConfig::new(one_hour, 250), | ||
| device_registry_cache: CacheEntryConfig::new(one_hour, 5_000), | ||
| lid_pn_cache: CacheEntryConfig::new(one_hour, 10_000), | ||
| retried_group_messages: CacheEntryConfig::new(five_min, 2_000), | ||
| device_registry_cache: CacheEntryConfig::new(one_hour, 1_000), | ||
| lid_pn_cache: CacheEntryConfig::new(one_hour, 2_000), | ||
| retried_group_messages: CacheEntryConfig::new(five_min, 500), | ||
| recent_messages: CacheEntryConfig::new(five_min, 0), | ||
| message_retry_counts: CacheEntryConfig::new(five_min, 1_000), | ||
| pdo_pending_requests: CacheEntryConfig::new(Some(Duration::from_secs(30)), 500), | ||
| message_retry_counts: CacheEntryConfig::new(five_min, 500), | ||
| pdo_pending_requests: CacheEntryConfig::new(Some(Duration::from_secs(30)), 200), | ||
| sender_key_devices_cache: CacheEntryConfig::new(one_hour, 500), | ||
| // Coordination caches hold live mutexes/senders; capacity eviction | ||
| // while a reference is held creates a second lock for the same key, | ||
| // breaking serialization. Size generously to avoid eviction pressure. | ||
| session_locks_capacity: 10_000, | ||
| chat_lanes_capacity: 5_000, | ||
| session_locks_capacity: 2_000, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Lowering Useful? React with 👍 / 👎. |
||
| chat_lanes_capacity: 1_000, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Useful? React with 👍 / 👎. |
||
| sent_message_ttl_secs: 300, | ||
| cache_stores: CacheStores::default(), | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -46,7 +46,7 @@ impl NoiseSocket { | |||||||||||||
|
|
||||||||||||||
| // Create channel for send jobs. Buffer size of 32 allows multiple | ||||||||||||||
| // callers to enqueue work without blocking on channel capacity. | ||||||||||||||
| let (send_job_tx, send_job_rx) = async_channel::bounded::<SendJob>(32); | ||||||||||||||
| let (send_job_tx, send_job_rx) = async_channel::bounded::<SendJob>(8); | ||||||||||||||
|
coderabbitai[bot] marked this conversation as resolved.
Outdated
Comment on lines
+47
to
+49
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid hardcoded latency claims in the queue-capacity comment. Line 48 says jobs complete in “<1ms each,” but this path includes Suggested patch- // Create channel for send jobs. Buffer of 8 is sufficient since the
- // sender task processes jobs serially in <1ms each.
+ // Keep this queue small to cap pre-allocation and apply backpressure
+ // during bursts; default tuned for typical single-client usage.📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||
|
|
||||||||||||||
| // Spawn the dedicated sender task | ||||||||||||||
| let transport_clone = transport.clone(); | ||||||||||||||
|
|
@@ -78,7 +78,7 @@ impl NoiseSocket { | |||||||||||||
| send_job_rx: async_channel::Receiver<SendJob>, | ||||||||||||||
| ) { | ||||||||||||||
| let mut write_counter: u32 = 0; | ||||||||||||||
| let mut enc_buf = Vec::with_capacity(4096); | ||||||||||||||
| let mut enc_buf = Vec::with_capacity(1024); | ||||||||||||||
| // BytesMut: split().freeze() yields a zero-copy Bytes while retaining | ||||||||||||||
| // the underlying allocation for the next frame. | ||||||||||||||
| let mut out_buf = BytesMut::with_capacity(4096); | ||||||||||||||
|
|
||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pdo_pending_requestsdefault appears out of sync with runtime capacity.Line 247 changes default capacity to
200, butsrc/pdo.rs(Line 39 in the provided snippet) still uses a hardcoded.max_capacity(500). That makes this config value ineffective for the actual PDO cache path.Suggested follow-up patch (outside this file)
Also applies to: 247-247
🤖 Prompt for AI Agents