Skip to content

perf: fix two performance bottlenecks#1649

Closed
aseembits93 wants to merge 3 commits intomainfrom
perf/fix-top-3-bottlenecks
Closed

perf: fix two performance bottlenecks#1649
aseembits93 wants to merge 3 commits intomainfrom
perf/fix-top-3-bottlenecks

Conversation

@aseembits93
Copy link
Contributor

@aseembits93 aseembits93 commented Feb 24, 2026

Summary

  • Cache normalized imports in optimizer: prepare_module_for_optimization now caches normalized imported modules in self.normalized_imports_cache, eliminating redundant file I/O + AST parse/unparse when multiple functions share helper modules
  • Move conditional imports to module level in comparator: All 11 conditional library imports (jax, numpy, torch, pandas, etc.) moved from inside the recursive comparator() function body to module level, wrapped in try/except ImportError for robustness — eliminates per-call import machinery overhead

Test plan

  • uv run pytest tests/test_comparator.py -x -q — 169 passed, 6 skipped
  • Verified all three modules import cleanly
  • Verified comparator() works on basic types after import changes
  • Verified HAS_* flags correctly fall back to False when import fails (e.g., numba with incompatible numpy)

🤖 Generated with Claude Code

… API client

Cache normalized imported modules across prepare_module_for_optimization calls
to eliminate redundant file I/O and AST parsing for shared imports. Move
conditional library imports in comparator.py from inside the recursive
comparator() function to module level to avoid per-call import machinery
overhead. Use a module-level requests.Session in cfapi.py for HTTP connection
pooling instead of creating new TCP/TLS connections per request.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@aseembits93 aseembits93 changed the title perf: fix three performance bottlenecks perf: fix two performance bottlenecks Mar 2, 2026
@aseembits93 aseembits93 closed this Mar 2, 2026
@claude
Copy link
Contributor

claude bot commented Mar 2, 2026

Claude finished @aseembits93's task in 3m 0s —— View job


PR Review Summary

  • Run prek lint/typecheck and auto-fix
  • Resolve stale review threads
  • Code review
  • Duplicate detection
  • Test coverage analysis
  • Post summary comment
  • Run /simplify
  • Check codeflash-ai[bot] PRs

Prek Checks

uv run prek run --from-ref origin/main passed — no files to check (diff is empty on this branch since the PR is closed and unmerged). Pre-existing mypy errors in optimizer.py (18 errors) are unrelated to this PR's change.

Code Review

This PR is closed without merge. The diff consisted of a single line addition:

self.normalized_imports_cache: dict[Path, ValidCode] = {}

added to Optimizer.__init__. However, normalized_imports_cache is never referenced anywhere in the codebase — no code reads from or writes to this cache. The PR description mentions two changes (caching normalized imports + moving conditional imports to module level in comparator), but the final diff only contains the unused cache attribute initialization. This suggests the substantive changes were removed before the last push, leaving only a dead attribute.

The reviewer's "no need" comment on cfapi.py (no longer in the diff) and the subsequent closure seem appropriate — there's nothing actionable in the current state of this PR.

No bugs, security issues, or breaking API changes found (the single added line has no runtime effect).

Duplicate Detection

No duplicates detected — the PR adds only one line (an unused attribute initialization) with no logic to duplicate.

Test Coverage

No coverage analysis performed — the PR is closed, the branch has no diff from main, and the single-line change (an unused attribute) would not affect test coverage.

Codeflash Bot PRs

No open codeflash-ai[bot] PRs target main. All 30 open bot PRs target feature branches (add/support_react, omni-java, feat/add/void/func, fix/java/object-cast-type, fix/jest-junit-and-misc, omni-main-java, unstructured-inference).

Notable issues among bot PRs:


Last updated: 2026-03-02T23:55Z

@aseembits93 aseembits93 deleted the perf/fix-top-3-bottlenecks branch March 17, 2026 00:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants