⚡️ Speed up method VideoSourcesManager.join_all_reconnection_threads
by 9%
#1127
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.
Saurabh's comment - It seems to speed up important part of the camera frame capture code. I would ask you to also manually verify this code, even though this looks good to me.
📄 9% (0.09x) speedup for
VideoSourcesManager.join_all_reconnection_threads
ininference/core/interfaces/camera/utils.py
⏱️ Runtime :
1.17 millisecond
→1.08 millisecond
(best of46
runs)📝 Explanation and details
Here is the optimized version of your Python program.
Optimizations Applied.
Avoid Unnecessary Copies.
copy
import and utilized thecopy()
method of sets directly.Data Structure Optimizations.
_enforce_stop
from aDict[int, bool]
to aSet[int]
for more efficient membership checks and removals.Helper Method.
_purge_reconnection_threads
to consolidate the purge logic, thereby avoiding repeated code.Use of Set
discard
.discard
instead ofremove
to avoid key errors if the key does not exist in the set.✅ Correctness verification report:
🌀 Generated Regression Tests Details