⚡️ Speed up function encrypt_auth_settings by 65% in PR #9506 (mcp-composer-integration-v2)#9707
Closed
codeflash-ai[bot] wants to merge 123 commits into
Closed
⚡️ Speed up function encrypt_auth_settings by 65% in PR #9506 (mcp-composer-integration-v2)#9707codeflash-ai[bot] wants to merge 123 commits into
encrypt_auth_settings by 65% in PR #9506 (mcp-composer-integration-v2)#9707codeflash-ai[bot] wants to merge 123 commits into
Conversation
… to connect. also fixes race condition in server creatoin
The optimization applies **memoization to the `get_settings_service()` function** using `@functools.lru_cache(maxsize=1)`. This is the single key change that delivers the 64% speedup. **What was optimized:** - Added `@functools.lru_cache(maxsize=1)` decorator to `get_settings_service()` to cache the expensive service initialization **Why this optimization works:** The line profiler reveals that `get_settings_service()` was consuming 99.7% of its execution time (58.46ms out of 58.61ms total) in the expensive `get_service()` call. This function was being called repeatedly - 89 times in the profiled run - but always returning the same SettingsService instance. Each call required: - Factory initialization via `SettingsServiceFactory()` - Service manager lookup and potential registration - Service instantiation logic With `lru_cache(maxsize=1)`, the first call performs the expensive initialization, and all subsequent calls return the cached instance in O(1) time. This transforms 89 expensive service lookups into 1 expensive lookup + 88 cache hits. **Performance impact by test type:** - **Basic encryption tests**: Moderate speedup since they call `get_settings_service()` fewer times - **Large-scale tests** (like `test_encrypt_auth_settings_large_number_of_fields`): Maximum benefit as they trigger more encryption/decryption operations, each requiring the settings service - **Performance-critical tests**: Most significant gains since they stress-test the repeated service access pattern The optimization maintains identical behavior - same service instance is returned, just cached after first access instead of recreated each time.
Contributor
|
Important Review skippedBot user detected. To trigger a single review, invoke the You can disable this status message by setting the 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Join our Discord community for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
Status, Documentation and Community
|
|
Contributor
Author
|
Base automatically changed from
mcp-composer-integration-v2
to
release-1.6.0
September 5, 2025 00:33
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 #9506
If you approve this dependent PR, these changes will be merged into the original PR branch
mcp-composer-integration-v2.📄 65% (0.65x) speedup for
encrypt_auth_settingsinlangflow/services/auth/mcp_encryption.py⏱️ Runtime :
7.19 milliseconds→4.36 milliseconds(best of29runs)📝 Explanation and details
The optimization applies memoization to the
get_settings_service()function using@functools.lru_cache(maxsize=1). This is the single key change that delivers the 64% speedup.What was optimized:
@functools.lru_cache(maxsize=1)decorator toget_settings_service()to cache the expensive service initializationWhy this optimization works:
The line profiler reveals that
get_settings_service()was consuming 99.7% of its execution time (58.46ms out of 58.61ms total) in the expensiveget_service()call. This function was being called repeatedly - 89 times in the profiled run - but always returning the same SettingsService instance. Each call required:SettingsServiceFactory()With
lru_cache(maxsize=1), the first call performs the expensive initialization, and all subsequent calls return the cached instance in O(1) time. This transforms 89 expensive service lookups into 1 expensive lookup + 88 cache hits.Performance impact by test type:
get_settings_service()fewer timestest_encrypt_auth_settings_large_number_of_fields): Maximum benefit as they trigger more encryption/decryption operations, each requiring the settings serviceThe optimization maintains identical behavior - same service instance is returned, just cached after first access instead of recreated each time.
✅ Correctness verification report:
⚙️ Existing Unit Tests and Runtime
🌀 Generated Regression Tests and Runtime
To edit these changes
git checkout codeflash/optimize-pr9506-2025-09-04T16.16.29and push.