Skip to content

Speed up plot_pareto_front by replacing O(N * |P|) list lookup in _get_non_pareto_front_trials - #6938

Merged
kAIto47802 merged 1 commit into
optuna:masterfrom
deep1blue:perf/pareto-front-non-best-trials-set-lookup
Nov 4, 2026
Merged

kAIto47802 merged 1 commit into
optuna:masterfrom
deep1blue:perf/pareto-front-non-best-trials-set-lookup

Conversation

@deep1blue

Copy link
Copy Markdown
Contributor

Motivation

In optuna/visualization/_pareto_front.py, _get_non_pareto_front_trials(trials, pareto_trials) filters out Pareto-optimal trials using if trial not in pareto_trials: inside a loop over all trials. Because pareto_trials is a list[FrozenTrial], each membership check performs a linear scan comparing full FrozenTrial objects (params, distributions, user_attrs, system_attrs, intermediate_values, etc.), resulting in $O(N \cdot |P|)$ complexity where $N = \text{len(trials)}$ and $|P| = \text{len(pareto_trials)}$.

Description of the Changes

Precompute pareto_trial_numbers = {trial.number for trial in pareto_trials} once and filter by trial.number not in pareto_trial_numbers, reducing _get_non_pareto_front_trials from $O(N \cdot |P|)$ FrozenTrial.__eq__ comparisons to $O(N + |P|)$ integer set lookups while preserving the exact output order and semantics.

Micro-benchmark (N = 3,000 trials, |P| = 1,500 Pareto-front trials)

  • Before (list membership on FrozenTrial): 431.70 ms
  • After (set membership on trial.number): 0.21 ms (~2,036x speedup)

Acknowledgments

… `_get_non_pareto_front_trials`

Precompute the set of Pareto-optimal trial numbers in `_get_non_pareto_front_trials` instead of performing a linear `trial not in pareto_trials` scan over `FrozenTrial` objects for every trial.

Signed-off-by: Parth Vadera <[email protected]>

@y0z y0z left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@y0z

y0z commented Nov 4, 2026

Copy link
Copy Markdown
Member

@kAIto47802 Could you review this PR?

@y0z y0z added the enhancement Change that does not break compatibility and not affect public interfaces, but improves performance. label Nov 4, 2026

@kAIto47802 kAIto47802 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@kAIto47802 kAIto47802 added this to the v5.1.0 milestone Nov 4, 2026
@kAIto47802
kAIto47802 merged commit cb485d7 into optuna:master Nov 4, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Change that does not break compatibility and not affect public interfaces, but improves performance.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants