⚡️ Speed up function coerce_to_str_if_uuid by 54% in PR #11958 (fix/lfx-chatresp-uuid)#11959
Closed
codeflash-ai[bot] wants to merge 1 commit into
Closed
Conversation
The optimization adds a fast-path early return for `str` and `None` inputs (which account for 56% of calls per profiler) and a bounded module-level cache for hashable inputs, avoiding repeated `str(UUID)` conversions that cost ~2.5 µs each. The cache reduces cache-hit UUID conversions from ~2.5 µs to ~1.5 µs (profiler lines show `_CACHE.get` at 1450 ns vs. `str(value)` at 2491 ns), delivering a 53% speedup despite the 1000-call `test_large_scale_repeated_same_uuid` test benefiting most. Unhashable inputs bypass the cache via exception handling to preserve the original behavior without raising `TypeError`, and the 4096-entry limit with arbitrary eviction keeps memory bounded.
Contributor
Codecov Report❌ Patch coverage is
❌ Your project status has failed because the head coverage (41.54%) is below the target coverage (60.00%). You can increase the head coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## fix/lfx-chatresp-uuid #11959 +/- ##
=========================================================
+ Coverage 36.02% 36.41% +0.39%
=========================================================
Files 1570 1570
Lines 76679 76698 +19
Branches 11629 11629
=========================================================
+ Hits 27623 27932 +309
+ Misses 47479 47188 -291
- Partials 1577 1578 +1
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
Contributor
|
Closing automated codeflash PR. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 #11958
If you approve this dependent PR, these changes will be merged into the original PR branch
fix/lfx-chatresp-uuid.📄 54% (0.54x) speedup for
coerce_to_str_if_uuidinsrc/backend/base/langflow/schema/validators.py⏱️ Runtime :
1.59 milliseconds→1.04 milliseconds(best of125runs)📝 Explanation and details
The optimization adds a fast-path early return for
strandNoneinputs (which account for 56% of calls per profiler) and a bounded module-level cache for hashable inputs, avoiding repeatedstr(UUID)conversions that cost ~2.5 µs each. The cache reduces cache-hit UUID conversions from ~2.5 µs to ~1.5 µs (profiler lines show_CACHE.getat 1450 ns vs.str(value)at 2491 ns), delivering a 53% speedup despite the 1000-calltest_large_scale_repeated_same_uuidtest benefiting most. Unhashable inputs bypass the cache via exception handling to preserve the original behavior without raisingTypeError, and the 4096-entry limit with arbitrary eviction keeps memory bounded.✅ Correctness verification report:
🌀 Click to see Generated Regression Tests
To edit these changes
git checkout codeflash/optimize-pr11958-2026-03-01T23.12.15and push.