Skip to main content

A multi-language code performance analyser with static analysis and AI-powered fix generation.

Project description

๐Ÿ”ง codewrench

Point it at your code. Get back what's slow and how to fix it.

Codewrench is a multi-language performance analyser that combines static analysis with AI-powered explanations. It finds real performance issues in your code โ€” nested loops, inefficient patterns, bad practices โ€” then explains exactly why they're a problem and shows you the fix.

No cloud, no setup hell, no enterprise pricing. Just run it on a file.


Installation

pip install codewrench

Create a .env file in your project root:

GROQ_API_KEY=your_key_here

Get a free Groq API key at console.groq.com


Usage

codewrench yourfile.py
codewrench app.js
codewrench main.go
codewrench ./myproject

Codewrench detects the language from the file extension automatically. Point it at a folder and it walks the entire project.

Example output

========================================
         CODEWRENCH REPORT
========================================
Files Scanned  : 1
Languages      : python
Issues Found   : 8 across 1 files
========================================

--- Warnings ---
  Nested loop at line 19 โ€” potential O(nยฒ)
  String concatenation at line 22 โ€” use ''.join() instead
  re.compile() inside loop at line 31 โ€” move it outside, compile once and reuse
  Bare except at line 40 โ€” catches everything, be specific

Top 5 slowest functions BEFORE fix:
  process_data                   cumtime: 2.341s
  build_string                   cumtime: 0.812s

Top 5 slowest functions AFTER fix:
  process_data                   cumtime: 0.421s
  build_string                   cumtime: 0.109s

Want AI analysis? (y/n): y

--- AI Analysis ---

1. Nested loop at line 19
   Problem: Two nested loops over the same data gives you O(nยฒ) complexity.
   For 1000 items that's 1,000,000 iterations instead of 1,000.

Want to apply fixes to files? (y/n): y
  Original saved as yourfile.py.bak
  Fixes applied to yourfile.py

Save report? (y/n): y
  Report saved to codewrench_report.md

What it catches

High priority

  • Nested loops โ€” O(nยฒ) and worse
  • Expensive I/O calls inside loops (open, requests, etc.)
  • re.compile() inside loops โ€” compile once, reuse
  • print() / logging inside loops โ€” I/O on every iteration
  • await inside loops โ€” use asyncio.gather() or Promise.all()
  • Repeated attribute access that should be cached
  • String concatenation with += in loops
  • String concatenation in nested loops โ€” quadratic complexity
  • Unnecessary object creation in loops (dict(), list(), etc.)

Medium priority

  • List concat with + instead of .extend()
  • List appends inside nested loops
  • Unnecessary list(range(n)) creation
  • Bare except: and overly broad except Exception
  • try/except inside loops
  • Global variable access inside loops
  • Mutable default arguments
  • Import inside functions
  • len() calls inside loops

Supported languages

Language Extension
Python .py
JavaScript .js
TypeScript .ts
Go .go
C .c
C++ .cpp, .cc

.wrenchignore

Create a .wrenchignore file in your project root to skip files or folders:

migrations/
tests/
legacy_code.py
*.min.js

Works like .gitignore โ€” supports wildcards and directory patterns.


How it works

your file
    โ†“
Tree-sitter parses it into a syntax tree
    โ†“
IR translator converts to language-agnostic representation
    โ†“
20 detectors run static analysis on the IR
    โ†“
Before/after profiling (Python, Node.js, go)
    โ†“
Findings sent to Groq (Llama 3.3 70B)
    โ†“
Plain English explanation + fix

The static analysis layer is deterministic โ€” it either finds a nested loop or it doesn't. No hallucination. The AI layer explains what the detectors already confirmed exists.


Roadmap

  • Static analysis (Python, JS, TS, Go, C, C++)
  • AI-powered explanations and fixes
  • Multi-language IR architecture
  • Runtime profiling โ€” before/after benchmark (Python)
  • 20 detectors across high and medium priority
  • Folder support with recursive analysis
  • .wrenchignore support
  • Smart API batching โ€” one call per folder, not per file
  • pip install codewrench
  • Multi-language profiling (Node, Go)
  • Language-specific detectors
  • Git diff integration โ€” analyse only what changed
  • VS Code extension
  • Web UI

Project structure

codewrench/
โ”œโ”€โ”€ detectors/
โ”‚   โ”œโ”€โ”€ base.py          โ† depth tracking, core visitor
โ”‚   โ”œโ”€โ”€ high.py          โ† high priority detectors
โ”‚   โ””โ”€โ”€ medium.py        โ† medium priority detectors
โ”œโ”€โ”€ languages/
โ”‚   โ”œโ”€โ”€ python_rules.py  โ† Tree-sitter node mappings per language
โ”‚   โ”œโ”€โ”€ js_rules.py
โ”‚   โ”œโ”€โ”€ ts_rules.py
โ”‚   โ”œโ”€โ”€ go_rules.py
โ”‚   โ”œโ”€โ”€ c_rules.py
โ”‚   โ””โ”€โ”€ cpp_rules.py
โ”œโ”€โ”€ profilers/
โ”‚   โ””โ”€โ”€ profiler.py      โ† cProfile integration
โ”œโ”€โ”€ ir.py                โ† language-agnostic IR node
โ”œโ”€โ”€ ir_translator.py     โ† Tree-sitter โ†’ IR translation
โ”œโ”€โ”€ parser_engine.py     โ† language detection + parser setup
โ”œโ”€โ”€ ai_engine.py         โ† Groq integration
โ”œโ”€โ”€ report.py            โ† Layer 5 report and output
โ”œโ”€โ”€ errors.py            โ† error handling
โ”œโ”€โ”€ wrenchignore.py      โ† .wrenchignore support
โ””โ”€โ”€ main.py              โ† entry point

Contributing

Pull requests welcome. If you want to add a new language, add a rules file in languages/ mapping Tree-sitter node types to the generic IR types. That's it โ€” the detectors work on all languages automatically.

Open an issue first for anything major.


Built by Vishad Jain

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

codewrench-0.1.1.tar.gz (17.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

codewrench-0.1.1-py3-none-any.whl (20.4 kB view details)

Uploaded Python 3

File details

Details for the file codewrench-0.1.1.tar.gz.

File metadata

  • Download URL: codewrench-0.1.1.tar.gz
  • Upload date:
  • Size: 17.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for codewrench-0.1.1.tar.gz
Algorithm Hash digest
SHA256 08df5918d80f780ea40740fa19bdc45fd045abd0e5ff538ccb84c3f6c0dbd7d2
MD5 310c20b7d9715efa3e677837e5cddd0a
BLAKE2b-256 ac3c494798b5bd25f30c16a3d0c40b1e1da91f14e360568a1d75d188c2b78a31

See more details on using hashes here.

File details

Details for the file codewrench-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: codewrench-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 20.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for codewrench-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 07244a44f12b770b8b8841219b99ba42bb64450f2ea112cd4642514502300013
MD5 af00d21d25cc689ffea79612fa04bdec
BLAKE2b-256 c72da59eac416296317aa174370af97035fd4868eaacc88e0f99a3f9862a5eed

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page