perf: reduce CompletedTrial cloning overhead

- Add Trial::into_completed() and into_multi_objective_trial() to move
  fields instead of cloning 5 HashMaps/Vecs per trial completion
- Fire after_trial callback before pushing to storage, eliminating the
  clone-from-storage pattern at all 4 call sites
- Optimize top_trials(n) to sort indices and clone only N trials instead
  of cloning all completed trials
- Remove unused set_complete/set_pruned methods
This commit is contained in:
Manuel Raimann
2026-02-12 14:39:28 +01:00
parent 74cf0643eb
commit 5da63d8976
5 changed files with 87 additions and 99 deletions
+5
View File
@@ -117,6 +117,11 @@ pub trait Objective<V: PartialOrd = f64> {
/// Called after each **completed** trial (not failed or pruned).
///
/// The trial is passed directly as the argument *before* it is pushed
/// to storage, so `study.n_trials()` and `study.trials()` do not yet
/// include this trial. The trial is always pushed to storage after this
/// callback returns, regardless of the return value.
///
/// Return `ControlFlow::Break(())` to stop the optimization loop.
///
/// Default: always continues.