Skip to content

perf: fix three performance bottlenecks#1649

Open
aseembits93 wants to merge 1 commit intomainfrom
perf/fix-top-3-bottlenecks
Open

perf: fix three performance bottlenecks#1649
aseembits93 wants to merge 1 commit intomainfrom
perf/fix-top-3-bottlenecks

Conversation

@aseembits93
Copy link
Contributor

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
  • HTTP connection pooling in cfapi: Added a module-level requests.Session so make_cfapi_request reuses TCP/TLS connections instead of creating new ones per request (~100-300ms saved per call after the first)

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>
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.

1 participant