⚡️ Speed up function _looks_like_variable_name by 71% in PR #12129 (fix-api-key-components)#12131
Closed
codeflash-ai[bot] wants to merge 6 commits intorelease-1.8.1from
Closed
Conversation
Made-with: Cursor
The optimized code pre-compiles the regex pattern at module load time instead of recompiling it on every invocation, eliminating the ~3 µs per-call overhead of `re.fullmatch`. Line profiler shows the regex line dropped from 86.3% to 41% of runtime despite now doing explicit `is not None` checks, because pattern compilation is amortized across all calls. Additionally, splitting the compound `if not value or not isinstance(value, str) or not value.strip()` into separate checks avoids redundant `strip()` calls on non-strings (saving ~286 ns per non-string input). The `match` with `\Z` anchor replaces `fullmatch` semantically while being slightly faster. All 90+ test cases pass with identical logic, confirming correctness across edge cases including very long strings, unicode, and high-volume repeated calls.
Codecov Report❌ Patch coverage is ❌ Your project status has failed because the head coverage (41.43%) 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 @@
## release-1.8.1 #12131 +/- ##
==============================================
Coverage 37.18% 37.19%
==============================================
Files 1592 1592
Lines 78216 78274 +58
Branches 11865 11872 +7
==============================================
+ Hits 29087 29111 +24
- Misses 47461 47495 +34
Partials 1668 1668
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
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 #12129
If you approve this dependent PR, these changes will be merged into the original PR branch
fix-api-key-components.📄 71% (0.71x) speedup for
_looks_like_variable_nameinsrc/backend/base/langflow/api/utils/core.py⏱️ Runtime :
3.84 milliseconds→2.25 milliseconds(best of84runs)📝 Explanation and details
The optimized code pre-compiles the regex pattern at module load time instead of recompiling it on every invocation, eliminating the ~3 µs per-call overhead of
re.fullmatch. Line profiler shows the regex line dropped from 86.3% to 41% of runtime despite now doing explicitis not Nonechecks, because pattern compilation is amortized across all calls. Additionally, splitting the compoundif not value or not isinstance(value, str) or not value.strip()into separate checks avoids redundantstrip()calls on non-strings (saving ~286 ns per non-string input). Thematchwith\Zanchor replacesfullmatchsemantically while being slightly faster. All 90+ test cases pass with identical logic, confirming correctness across edge cases including very long strings, unicode, and high-volume repeated calls.✅ Correctness verification report:
🌀 Click to see Generated Regression Tests
To edit these changes
git checkout codeflash/optimize-pr12129-2026-03-10T17.38.03and push.