Skip to content

Make trial queues internally synchronized and shareable across threads - #303

Merged
c-bata merged 1 commit into
optuna:mainfrom
c-bata:trial-queue-synchronized
Nov 4, 2026
Merged

c-bata merged 1 commit into
optuna:mainfrom
c-bata:trial-queue-synchronized

Conversation

@c-bata

@c-bata c-bata commented Nov 4, 2026

Copy link
Copy Markdown
Member

Summary

Study currently wraps trial queues in an outer RwLock. This change lets each queue implementation handle its own synchronization and allows the queue handle to be shared directly, following the approach used for samplers in #216.

  • Change TrialQueue::enqueue and dequeue to take &self.
  • Replace Arc<RwLock<dyn TrialQueue>> with Arc<dyn TrialQueue> in Study and the PyO3 bindings.
  • Use a mutex for the in-memory queue and backend-level synchronization for directory and SQLite queues.
  • Update the Rust and Python adapters to use the shared queue directly.

Compatibility

This changes the public Rust TrialQueue trait and the types of Study::new and Study::queue. Custom Rust implementations and callers that use the previous RwLock-wrapped queue will need to update.

@c-bata
c-bata merged commit d0ec7db into optuna:main Nov 4, 2026
10 checks passed
@c-bata
c-bata deleted the trial-queue-synchronized branch November 4, 2026 07:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant