Skip to content

Use subset comparator to judge if trials are included in search space#6218

Merged
nabenabe0928 merged 1 commit intooptuna:masterfrom
nabenabe0928:enhance/use-subset-comparator-for-internal-repr
Jul 25, 2025
Merged

Use subset comparator to judge if trials are included in search space#6218
nabenabe0928 merged 1 commit intooptuna:masterfrom
nabenabe0928:enhance/use-subset-comparator-for-internal-repr

Conversation

@nabenabe0928
Copy link
Copy Markdown
Contributor

Motivation

to_internal_repr in TPESampler is very slow, so I would like to speed it up with the following change:

In [1]: d = {f"x{i}": i for i in range(50)}

In [2]: s = {f"x{i}": i for i in range(50)}

In [3]: %timeit s.keys() <= d.keys()
569 ns ± 4.71 ns per loop (mean ± std. dev. of 7 runs, 1,000,000 loops each)

In [4]: %timeit all(p in d.keys() for p in s)
1.93 μs ± 32.8 ns per loop (mean ± std. dev. of 7 runs, 1,000,000 loops each)

Description of the changes

  • Use the subset comparator to speed up the internal repr judge

@nabenabe0928 nabenabe0928 added the enhancement Change that does not break compatibility and not affect public interfaces, but improves performance. label Jul 25, 2025
@nabenabe0928 nabenabe0928 added this to the v4.5.0 milestone Jul 25, 2025
@nabenabe0928
Copy link
Copy Markdown
Contributor Author

@kAIto47802 @y0z Could you review this PR?

Copy link
Copy Markdown
Member

@y0z y0z left a comment

Choose a reason for hiding this comment

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

LGTM

@y0z y0z removed their assignment Jul 25, 2025
Copy link
Copy Markdown
Collaborator

@kAIto47802 kAIto47802 left a comment

Choose a reason for hiding this comment

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

LGTM!

@kAIto47802 kAIto47802 removed their assignment Jul 25, 2025
@nabenabe0928 nabenabe0928 merged commit 9e8d35e into optuna:master Jul 25, 2025
15 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