-
Notifications
You must be signed in to change notification settings - Fork 6.8k
perf: lazy-load MCP SDK and event types to reduce cold start by ~29% #5584
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
fb2d7b8
perf: defer MCP SDK import by fixing import path in agent/core.py
iris-clawd 776db45
perf: lazy-load heavy MCP imports in mcp/__init__.py
iris-clawd 24f774d
perf: lazy-load all event type modules in events/__init__.py
iris-clawd 323d477
chore: remove UNKNOWN.egg-info from version control
iris-clawd 12c77a2
fix: add MCPToolResolver to TYPE_CHECKING imports
joaomdmoura bbecebd
fix: bump lxml to >=5.4.0 for GHSA-vfmq-68hx-4jfw
joaomdmoura 420420f
fix: bump exclude-newer to 2026-04-22 for lxml 6.1.0 resolution
joaomdmoura d6e7ccc
perf: add import time benchmark script
joaomdmoura feac72e
new action
joaomdmoura 634ff3d
Potential fix for pull request finding 'CodeQL / Workflow does not co…
joaomdmoura File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| name: Import Time Guard | ||
|
|
||
| on: | ||
| pull_request: | ||
| paths: | ||
| - "lib/crewai/src/**" | ||
| - "lib/crewai/pyproject.toml" | ||
| - "pyproject.toml" | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| import-time: | ||
| runs-on: ubuntu-latest | ||
| strategy: | ||
| matrix: | ||
| python-version: ["3.12"] | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| with: | ||
| fetch-depth: 0 | ||
|
|
||
| - uses: astral-sh/setup-uv@v6 | ||
| with: | ||
| version: "0.11.3" | ||
| enable-cache: true | ||
|
|
||
| - name: Install the project | ||
| run: uv sync --all-extras --no-dev | ||
| env: | ||
| UV_PYTHON: ${{ matrix.python-version }} | ||
|
|
||
| - name: Benchmark PR branch | ||
| id: pr | ||
| run: | | ||
| result=$(uv run python scripts/benchmark_import_time.py --runs 5 --json) | ||
| echo "result=$result" >> "$GITHUB_OUTPUT" | ||
| echo "pr_median=$(echo $result | python3 -c 'import sys,json; print(json.load(sys.stdin)["median_s"])')" >> "$GITHUB_OUTPUT" | ||
| echo "### PR Branch Import Time" >> "$GITHUB_STEP_SUMMARY" | ||
| echo "$result" | python3 -c " | ||
| import sys, json | ||
| d = json.load(sys.stdin) | ||
| print(f'- Median: {d[\"median_s\"]}s') | ||
| print(f'- Mean: {d[\"mean_s\"]}s ± {d[\"stdev_s\"]}s') | ||
| print(f'- Range: {d[\"min_s\"]}s – {d[\"max_s\"]}s') | ||
| " >> "$GITHUB_STEP_SUMMARY" | ||
| env: | ||
| UV_PYTHON: ${{ matrix.python-version }} | ||
|
|
||
| - name: Checkout base branch | ||
| run: git checkout ${{ github.event.pull_request.base.sha }} | ||
|
|
||
| - name: Install base branch | ||
| run: uv sync --all-extras --no-dev | ||
| env: | ||
| UV_PYTHON: ${{ matrix.python-version }} | ||
|
|
||
| - name: Benchmark base branch | ||
| id: base | ||
| run: | | ||
| result=$(uv run python scripts/benchmark_import_time.py --runs 5 --json 2>/dev/null || echo '{"median_s": 0}') | ||
| echo "result=$result" >> "$GITHUB_OUTPUT" | ||
| echo "base_median=$(echo $result | python3 -c 'import sys,json; print(json.load(sys.stdin)["median_s"])')" >> "$GITHUB_OUTPUT" | ||
| echo "### Base Branch Import Time" >> "$GITHUB_STEP_SUMMARY" | ||
| echo "$result" | python3 -c " | ||
| import sys, json | ||
| d = json.load(sys.stdin) | ||
| if d.get('median_s', 0) > 0: | ||
| print(f'- Median: {d[\"median_s\"]}s') | ||
| else: | ||
| print('- Benchmark script not present on base branch (skip comparison)') | ||
| " >> "$GITHUB_STEP_SUMMARY" | ||
| env: | ||
| UV_PYTHON: ${{ matrix.python-version }} | ||
|
|
||
| - name: Compare and gate | ||
| run: | | ||
| pr_median=${{ steps.pr.outputs.pr_median }} | ||
| base_median=${{ steps.base.outputs.base_median }} | ||
|
|
||
| python3 -c " | ||
| pr = float('$pr_median') | ||
| base = float('$base_median') | ||
|
|
||
| if base <= 0: | ||
| print('⏭️ No base benchmark available — skipping comparison.') | ||
| exit(0) | ||
|
|
||
| change_pct = ((pr - base) / base) * 100 | ||
| print(f'Base: {base:.3f}s') | ||
| print(f'PR: {pr:.3f}s') | ||
| print(f'Change: {change_pct:+.1f}%') | ||
| print() | ||
|
|
||
| if change_pct > 5: | ||
| print(f'❌ BLOCKED: Import time regressed by {change_pct:.1f}% (threshold: 5%)') | ||
| exit(1) | ||
| elif change_pct > 0: | ||
| print(f'⚠️ Slight regression ({change_pct:.1f}%) but within 5% threshold.') | ||
| else: | ||
| print(f'✅ Import time improved by {abs(change_pct):.1f}%') | ||
| " | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,3 +30,4 @@ chromadb-*.lock | |
| .crewai/memory | ||
| blogs/* | ||
| secrets/* | ||
| UNKNOWN.egg-info/ | ||
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.