Skip to content

Add lazy tree node to BruteForceSampler for speedup - #6705

Merged
kAIto47802 merged 15 commits into
optuna:masterfrom
nabenabe0928:use-lazy-node-in-brute-force
Jun 26, 2026
Merged

kAIto47802 merged 15 commits into
optuna:masterfrom
nabenabe0928:use-lazy-node-in-brute-force

Conversation

@nabenabe0928

@nabenabe0928 nabenabe0928 commented Jun 4, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

BruteForceSampler instantiates _TreeNode many times, i.e., $O(N)$, at each suggest_independent.
This is not negligible when user needs to evaluate thousands of trials.

I introduce a sentinel tree node so that instantiation would not incur any overhead unless needed.

I used the following function in my env, and ran from 8500 trials to 8600 trials.
I saw roughly 50% speedup in the instantiation part only (2 seconds --> 1 seconds) out of the total runtime of 15 seconds.

search_space = {f"c{i}": [str(i) for i in range(5)] for i in range(3)}
search_space |= {f"f{j}": [0.1 * i for i in range(5)] for j in range(3)}


def objective(trial: optuna.Trial) -> float:
    for k, v in search_space.items():
        if k[0] == "c":
            trial.suggest_categorical(k, v)
        else:
            trial.suggest_float(k, v[0], v[-1], step=v[1] - v[0])
    return 0.0

When we ran for another 10000 trials from this point, the overhead reduction is gonna be at least $1 \times 100 = 100$ seconds.

Description of the changes

  • Add lazy tree node sentinel
  • Update the corresponding test

@c-bata c-bata added the enhancement Change that does not break compatibility and not affect public interfaces, but improves performance. label Jun 9, 2026
@c-bata

c-bata commented Jun 9, 2026

Copy link
Copy Markdown
Member

@porink0424 @kAIto47802 Could you review this PR?

@github-actions

Copy link
Copy Markdown
Contributor

This pull request has not seen any recent activity.

@github-actions github-actions Bot added the stale Exempt from stale bot labeling. label Jun 16, 2026
@c-bata c-bata removed the stale Exempt from stale bot labeling. label Jun 17, 2026
porink0424
porink0424 previously approved these changes Jun 23, 2026

@porink0424 porink0424 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 👍

@porink0424 porink0424 removed their assignment Jun 23, 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.0.0 milestone Jun 26, 2026
@kAIto47802
kAIto47802 merged commit 46befbd into optuna:master Jun 26, 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.

4 participants