⚡️ Speed up method ModelManager.add_model
by 11% in PR #1175 (depth-estimation-workflow-block
)
#1194
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
⚡️ This pull request contains optimizations for PR #1175
If you approve this dependent PR, these changes will be merged into the original PR branch
depth-estimation-workflow-block
.📄 11% (0.11x) speedup for
ModelManager.add_model
ininference/core/managers/base.py
⏱️ Runtime :
2.13 milliseconds
→1.91 millisecond
(best of118
runs)📝 Explanation and details
In order to optimize the performance of the
add_model
andget_model
methods, we need to minimize the time spent on certain operations and reduce the number of loggings wherever possible.Changes made:
In the
get_model
method ofModelRegistry
, a singletry/except
block replaces the if-check and separate raise to catchKeyError
, thereby combining lookup and retrieval into a single step. This optimizes the process of fetching the model class and raising the error when necessary.In the
add_model
method ofModelManager
, logging messages are minimized and combined to reduce the overhead caused by frequent logging. The change reduces unnecessary calls tologger.debug()
.Line profiling improvements:
get_model
: Combined lookup and retrieval operations reduce steps.add_model
: Consolidatinglogger.debug()
calls minimizes overhead and redundant operations.✅ Correctness verification report:
🌀 Generated Regression Tests Details
To edit these changes
git checkout codeflash/optimize-pr1175-2025-04-16T21.35.26
and push.