⚡️ Speed up function scale_confidence by 13%
#593
+8
−1
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.
📄 13% (0.13x) speedup for
scale_confidenceininference/core/workflows/core_steps/formatters/vlm_as_detector/v2.py⏱️ Runtime :
1.57 milliseconds→1.39 milliseconds(best of156runs)📝 Explanation and details
The optimization removes the
isinstance(value, float)type check and always callsfloat(value)directly. This change provides a 12% speedup because:Key optimization:
float(), but this type check overhead actually costs more than thefloat()conversion itselfWhy this works:
float()is highly optimized in Python and handles all input types efficientlyfloat(value)is essentially a no-op with minimal overheadisinstance()check + conditional logic was actually slower than just callingfloat()directlyfloat()constructor is optimized for common cases like integers, strings, and existing floatsPerformance gains by input type:
The optimization is particularly effective for mixed-type inputs and high-frequency calls where the isinstance overhead accumulates significantly.
✅ Correctness verification report:
🌀 Generated Regression Tests and Runtime
To edit these changes
git checkout codeflash/optimize-scale_confidence-mh9xmb6dand push.