Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
⚡️ Speed up method
DuckDuckGoSearchComponent._build_wrapper
by 1,59…
…8% in PR #6028 (`PlaygroundPage`) To optimize the given Python program for faster runtime, consider the following changes. 1. **Avoid Redundant Instantiation**: Ensure that the `DuckDuckGoSearchRun` wrapper is instantiated only once and reused. 2. **Lazily Load Heavy Operations**: Only initialize and use the `DuckDuckGoSearchRun` object when needed. ### Explanation 1. **Initialization in Constructor**: We introduce a private variable `_ddg_search_wrapper` which will store the instance of the `DuckDuckGoSearchRun`. 2. **Lazy Initialization**: In the `_build_wrapper` method, we check if `_ddg_search_wrapper` is `None`. If it is, we instantiate `DuckDuckGoSearchRun`, ensuring that it only happens once, thus avoiding redundant instantiation. These changes ensure that the wrapper is only instantiated once and reused, reducing the overhead and improving the performance of the component.
- Loading branch information