⚡️ Speed up function convert_llm by 163% in PR #8930 (release-1.5.0)#8931
Closed
codeflash-ai[bot] wants to merge 10 commits into
Closed
⚡️ Speed up function convert_llm by 163% in PR #8930 (release-1.5.0)#8931codeflash-ai[bot] wants to merge 10 commits into
convert_llm by 163% in PR #8930 (release-1.5.0)#8931codeflash-ai[bot] wants to merge 10 commits into
Conversation
- Updated langflow version to 1.5.0 in pyproject.toml, package.json, and package-lock.json. - Updated langflow-base dependency to version 0.5.0. - Added platform markers for several dependencies in uv.lock to improve compatibility across different systems.
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Gabriel Luiz Freitas Almeida <gabriel@langflow.org>
…ailures (#8890) Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Gabriel Luiz Freitas Almeida <gabriel@langflow.org> fix: fixes auth check for auto_login (#8796)
* Add new openai reasoning models * [autofix.ci] apply automated fixes * Updates language model, but FE doesn't send a POST for updating template atm * use chatopenai constants * [autofix.ci] apply automated fixes * Add reasoning to language model test * Remove temp from all reasoning models * t [autofix.ci] apply automated fixes * refactor: Update template notes (#8816) * update templates * small-changes * template cleanup --------- Co-authored-by: Mendon Kissling <59585235+mendonk@users.noreply.github.com> * ruff * uv lock * starter projects update * [autofix.ci] apply automated fixes --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Mike Fortman <michael.fortman@datastax.com> Co-authored-by: Mendon Kissling <59585235+mendonk@users.noreply.github.com>
* chore: Bump version to 1.5.0 and update dependencies - Updated langflow version to 1.5.0 in pyproject.toml, package.json, and package-lock.json. - Updated langflow-base dependency to version 0.5.0. - Added platform markers for several dependencies in uv.lock to improve compatibility across different systems. * fix: fixes auth check for auto_login (#8796) * ref: improve docling template updates and error message (#8837) Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Gabriel Luiz Freitas Almeida <gabriel@langflow.org> * Attempt to provide powershell curl command * [autofix.ci] apply automated fixes * [autofix.ci] apply automated fixes (attempt 2/3) * Added OS selector to code tabs * Added no select classes to API modal * ✨ (code-tabs.tsx): add data-testid attribute to API tab elements for testing purposes 🔧 (tweaksTest.spec.ts, curlApiGeneration.spec.ts, pythonApiGeneration.spec.ts, generalBugs-shard-3.spec.ts): update test scripts to use data-testid attribute for API tab elements instead of role attribute --------- Co-authored-by: Gabriel Luiz Freitas Almeida <gabriel@langflow.org> Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Lucas Oliveira <lucas.edu.oli@hotmail.com> Co-authored-by: cristhianzl <cristhian.lousa@gmail.com>
Here is a rewritten, **optimized** version of your program, focusing on significant hot spots (from the line profiler) and leveraging locality, reduced allocations, and fast Python idioms. The main bottleneck is **`_find_api_key`**, particularly attribute access and lower-casing/search, and the **dict filtering** at the bottom of `convert_llm`. Key changes for speed. - **`_find_api_key`**. - Use a **cached set of lower patterns** for fast `in` checks. - Scan attributes and look up only **first** string/SecretStr-valued matching attribute—stop early. - Use `model.__dict__` where possible for speed, fallback to `dir()` only if needed, prefer `vars(model)` (which is essentially `__dict__`) for most models. - Minimize repeated operations inside loops. - **`convert_llm`**. - **Precompute** the dict filter set and use **list comprehensions** (Py3.7+ dicts preserve order and are fast). - Inline all known one-time representatives outside repeated control flow. - Only get the dict once. **Summary of speed improvements:** - Use `vars(model)`/`.__dict__` directly if available—faster than `dir()` and less work. - Inline filter for key in attribute (avoiding unnecessary generator). - Attribute access and string lowercasing only occur once per attribute. - `convert_llm` dict filtering is now single-pass. - **Overall effect**: Dramatically reduces function call count, attribute access, and per-item python overhead in both hot spots. If you want even further micro-optimization for `_find_api_key`, you may also break on the first found attribute whose value is not `None`, rather than searching all attributes—but normally there is just one such key so this won't matter for correctness or speed.
Merged
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. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
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 #8930
If you approve this dependent PR, these changes will be merged into the original PR branch
release-1.5.0.📄 163% (1.63x) speedup for
convert_llminsrc/backend/base/langflow/base/agents/crewai/crew.py⏱️ Runtime :
4.74 milliseconds→1.80 milliseconds(best of92runs)📝 Explanation and details
Here is a rewritten, optimized version of your program, focusing on significant hot spots (from the line profiler) and leveraging locality, reduced allocations, and fast Python idioms. The main bottleneck is
_find_api_key, particularly attribute access and lower-casing/search, and the dict filtering at the bottom ofconvert_llm.Key changes for speed.
_find_api_key.inchecks.model.__dict__where possible for speed, fallback todir()only if needed, prefervars(model)(which is essentially__dict__) for most models.convert_llm.Summary of speed improvements:
vars(model)/.__dict__directly if available—faster thandir()and less work.convert_llmdict filtering is now single-pass.If you want even further micro-optimization for
_find_api_key, you may also break on the first found attribute whose value is notNone, rather than searching all attributes—but normally there is just one such key so this won't matter for correctness or speed.✅ Correctness verification report:
🌀 Generated Regression Tests and Runtime
To edit these changes
git checkout codeflash/optimize-pr8930-2025-07-08T12.55.56and push.