Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

* General
* Stop reporting db file sizes during init phase ([#3331](https://github.com/mozilla/glean/pull/3331))
* Tiny performance improvement for putting tasks on the dispatcher ([#3318](https://github.com/mozilla/glean/pull/3318))

# v66.1.1 (2025-11-06)

Expand Down
26 changes: 20 additions & 6 deletions glean-core/src/dispatcher/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

use std::{
mem,
ops::Deref,
sync::{
atomic::{AtomicBool, AtomicUsize, Ordering},
Arc,
Expand Down Expand Up @@ -92,11 +93,23 @@ impl<T> From<SendError<T>> for DispatchError {
/// A clonable guard for a dispatch queue.
#[derive(Clone)]
struct DispatchGuard {
inner: Arc<DispatchGuardInner>,
}

impl Deref for DispatchGuard {
type Target = DispatchGuardInner;

fn deref(&self) -> &Self::Target {
&self.inner
}
}

struct DispatchGuardInner {
/// Whether to queue on the preinit buffer or on the unbounded queue
queue_preinit: Arc<AtomicBool>,
queue_preinit: AtomicBool,

/// The number of items that were added to the queue after it filled up.
overflow_count: Arc<AtomicUsize>,
overflow_count: AtomicUsize,

/// The maximum pre-init queue size
max_queue_size: usize,
Expand Down Expand Up @@ -262,8 +275,8 @@ impl Dispatcher {
let (preinit_sender, preinit_receiver) = unbounded();
let (sender, mut unbounded_receiver) = unbounded();

let queue_preinit = Arc::new(AtomicBool::new(true));
let overflow_count = Arc::new(AtomicUsize::new(0));
let queue_preinit = AtomicBool::new(true);
let overflow_count = AtomicUsize::new(0);

let worker = crate::thread::spawn("glean.dispatcher", move || {
match block_receiver.recv() {
Expand Down Expand Up @@ -322,14 +335,15 @@ impl Dispatcher {
})
.expect("Failed to spawn Glean's dispatcher thread");

let guard = DispatchGuard {
let inner = Arc::new(DispatchGuardInner {
queue_preinit,
overflow_count,
max_queue_size,
block_sender,
preinit_sender,
sender,
};
});
let guard = DispatchGuard { inner };

Dispatcher {
guard,
Expand Down