Skip to main content

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

Project description

๐Ÿ”ง wrench

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

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


What it catches

High priority

  • Nested loops (O(nยฒ) and worse)
  • Expensive function calls inside loops
  • Repeated attribute access that should be cached
  • String concatenation with + in loops

Medium priority

  • List appends inside nested loops
  • Unnecessary list(range(n)) creation
  • Bare except: and overly broad except Exception
  • Global variable access inside loops
  • Mutable default arguments

Supported languages

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

Installation

git clone https://github.com/yourusername/wrench.git
cd wrench
python -m venv venv
source venv/bin/activate        # Mac/Linux
venv\Scripts\activate           # Windows
pip install -r requirements.txt

Create a .env file in the project root:

GROQ_API_KEY=your_key_here

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


Usage

python main.py yourfile.py
python main.py app.js
python main.py main.go
python main.py server.cpp

That's it. Wrench detects the language from the file extension automatically.

Example output

Nested loop at line 19 โ€” potential O(nยฒ)
String concatenation at line 22 โ€” use ''.join() instead
Function call 'expensive_function' inside loop at line 25 โ€” consider moving it out
Bare except at line 40 โ€” catches everything including system exceptions, be specific

--- AI Analysis ---

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

   Fix:
   # before
   for i in items:
       for j in items:
           process(i, j)

   # after โ€” use itertools or restructure with a dict lookup
   lookup = {item: process(item) for item in items}

How it works

your file
    โ†“
Tree-sitter parses it into a syntax tree
    โ†“
IR translator converts to language-agnostic representation
    โ†“
Detectors run static analysis on the IR
    โ†“
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 (Layer 3)
  • More detectors
  • pip install wrench support
  • Web UI

Project structure

wrench/
โ”œโ”€โ”€ 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
โ”‚   โ””โ”€โ”€ ...
โ”œโ”€โ”€ 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
โ””โ”€โ”€ 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 [@vishaddjain]

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.0.tar.gz (12.6 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.0-py3-none-any.whl (17.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: codewrench-0.1.0.tar.gz
  • Upload date:
  • Size: 12.6 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.0.tar.gz
Algorithm Hash digest
SHA256 69d7cf99b54e48b11d4f2d97bc9ef4b3251066738ba04fcd756e88f760d08c94
MD5 7953f687e15b831c84d9f0d7e9c867e9
BLAKE2b-256 9b7b46cf5a6f89af37050cb3b0764ffd880f4f2c372194fe07d5eab0988dd90d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: codewrench-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 17.7 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 00da1a05a70e28e05fe0c9251a9071a3d2a7e53a8e1bdc97336fe68b4efa8e1e
MD5 c86d1a48f14dbc0766d97d22ee6503ae
BLAKE2b-256 8127769b18ac6a0b2d0b2464766986181d940ab790eefcf5b9b435996a9cfef5

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