⚡️ Speed up method ConfigResponse.from_settings by 13% in PR #11223 (add-option-to-block-custom-code)
#11471
+7
−7
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 #11223
If you approve this dependent PR, these changes will be merged into the original PR branch
add-option-to-block-custom-code.📄 13% (0.13x) speedup for
ConfigResponse.from_settingsinsrc/backend/base/langflow/api/v1/schemas.py⏱️ Runtime :
976 microseconds→867 microseconds(best of89runs)📝 Explanation and details
The optimized code achieves a 12% speedup by addressing two key performance bottlenecks identified in the line profiler data:
Key Optimizations
1. Moved imports to module level (~50% reduction in import overhead)
osandDEFAULT_FOLDER_NAMEinside the method on every callimport ostook 492,499ns and thefrom langflow.services...import took 547,982ns per call (combined ~1.04ms or 4.2% of total time)2. Optimized environment variable access (~30% faster)
os.getenv("HIDE_GETTING_STARTED_PROGRESS", "").lower() == "true"toos.environ.get("HIDE_GETTING_STARTED_PROGRESS", "").lower() == "true"os.environ.get()directly accesses the environment dictionary, avoiding the extra function call overhead ofos.getenv()which wrapsos.environ.get()with additional logicWhy This Matters
The method
from_settingsis called 694 times in the profiler run, suggesting it's invoked frequently during application initialization or configuration updates. The test suite shows it handles configuration settings for a web application (timeouts, auto-saving intervals, webhook settings), making it likely to be on a critical startup or request handling path.Test Case Performance
All test cases benefit uniformly from these optimizations since every invocation incurs the same import and environment variable lookup overhead. The optimization is particularly effective for:
test_idempotent_behavior_across_multiple_callswith 50 iterations)The optimizations preserve exact behavior - all tests pass with identical outputs, and edge cases (case-insensitive environment variables, whitespace handling, large numeric values) work identically.
✅ Correctness verification report:
🌀 Click to see Generated Regression Tests
To edit these changes
git checkout codeflash/optimize-pr11223-2026-01-27T22.08.12and push.