Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
135 changes: 80 additions & 55 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,112 +1,137 @@
# ⚡ CodeFlash Optimize-Me
**Ship fast code from day one.** This repo lets you experience the magic of AI-powered code optimization.
# CodeFlash Optimize-Me

## 🚀 What is this repo?
**Ship fast code from day one.** This repo lets you experience AI-powered code optimization across Python, Java, and JavaScript/TypeScript.

This repository contains intentionally unoptimized Python code that's perfect for experiencing Codeflash in action. Fork it, run Codeflash, and watch as it automatically discovers optimizations and opens Pull Requests while verifying the optimized code works exactly the same as the original.
## What is this repo?

## 🔍 What is Codeflash?
This repository contains intentionally unoptimized code in multiple languages, perfect for experiencing Codeflash in action. Fork it, run Codeflash, and watch as it automatically discovers optimizations and opens Pull Requests while verifying the optimized code works exactly the same as the original.

Codeflash is an AI-powered code optimizer that automatically finds the most performant version of your Python code through intelligent benchmarking—while verifying it's still correct. It's like having an expert performance engineer review and optimize every line of your code.
## What is Codeflash?

**Codeflash can:**
- Improve algorithms and data structures (like converting lists to sets)
- Speed up mathematical operations with NumPy
- Optimize machine learning code for PyTorch
- Make data handling more efficient with Pandas
- Catch and fix inefficient patterns automatically
Codeflash is an AI-powered code optimizer that automatically finds the most performant version of your code through intelligent benchmarking — while verifying it's still correct.

Leading engineering teams at [Pydantic](https://pydantic.dev/), [Langflow](https://langflow.org/), and [Roboflow](https://roboflow.com) trust Codeflash to ship expert-level, high-performance code.

## Project Structure

## ⏱️ Getting Started ( 5 minutes)
```
optimize-me/
├── pyproject.toml # Python config (includes codeflash settings)
├── src/ # Python source code
│ ├── algorithms/ # Sorting, search, text analysis, etc.
│ ├── data_processing/ # DataFrame and series operations
│ ├── math/ # Combinatorics and number theory
│ ├── numerical/ # Calculus, linear algebra, monte carlo
│ ├── signal/ # Filters, image processing, transforms
│ └── statistics/ # Clustering, decomposition, similarity
├── tests/ # Python tests
├── java/ # Java Maven subproject
│ ├── pom.xml # Maven config (JUnit 4, Java 11)
│ └── src/
│ ├── main/java/com/optimizeme/
│ │ ├── CollectionUtils.java # Generics, mergeSorted, groupBy
│ │ └── StringProcessor.java # isPalindrome, compress, LCP
│ └── test/java/com/optimizeme/
│ ├── CollectionUtilsTest.java
│ └── StringProcessorTest.java
└── js/ # JavaScript/TypeScript npm subproject
├── package.json # npm config (Vitest)
├── tsconfig.json
└── src/
│ ├── asyncUtils.js # retryWithBackoff, batchProcess
│ └── dataTransform.ts # pivot, flatten, groupByKey (generics)
└── tests/
├── asyncUtils.test.js
└── dataTransform.test.ts
```

1. **Fork this repo** to your GitHub account by clicking "Fork" on the top of the page. This allows Codeflash to open Pull Requests with the optimizations it found on your forked repo.
2. **Clone your fork** to your local machine.
## Getting Started

### 1. Fork and clone

```bash
git clone https://github.com/<your_github_username>/optimize-me.git
cd optimize-me
```
3. **Create a Python virtual environment, and activate it.**

Using `venv`:

### 2. Set up each language

**Python** (requires Python 3.11+):
```bash
python -m venv .venv
source .venv/bin/activate
pip install -e .
```

Or with `conda`:
**Java** (requires JDK 11+, Maven):
```bash
conda create -n optimize-me python=3.12
conda activate optimize-me
cd java
mvn compile
mvn test
cd ..
```

4. **Install dependencies**
**JavaScript/TypeScript** (requires Node.js, npm):
```bash
pip install -r requirements.txt
cd js
npm install
npm test
cd ..
```

## 🔮 Set up Codeflash
### 3. Set up Codeflash

Run the guided setup:
```bash
codeflash init
```
Since this project already has the codeflash settings pre-configured in pyproject.toml, you will only need to:
- Get a `CODEFLASH_API_KEY` by [signing up](https://app.codeflash.ai/login)
- Install a GitHub App through [this link](https://github.com/apps/codeflash-ai/installations/select_target)

## 💫 Using CodeFlash
Since this project already has codeflash settings pre-configured in `pyproject.toml`, you will only need to:
- Get a `CODEFLASH_API_KEY` by [signing up](https://app.codeflash.ai/login)
- Install the GitHub App through [this link](https://github.com/apps/codeflash-ai/installations/select_target)

**Optimize the entire repo:**
## Using Codeflash

**Optimize all languages at once** (discovers Python, Java, and JS/TS configs automatically):
```bash
codeflash --all
```
Codeflash will create Pull Requests with optimizations as it finds them.

**Optimize a single file**

**Optimize a single Python file:**
```bash
codeflash --file path/to/file
codeflash --file src/algorithms/helpers.py --function is_prime
```

**Optimize a specific function:**
**Optimize a single Java file:**
```bash
codeflash --file java/src/main/java/com/optimizeme/StringProcessor.java --function isPalindrome
```

**Optimize a single JS file:**
```bash
codeflash --file path/to/file --function function_name
codeflash --file js/src/asyncUtils.js --function retryWithBackoff
```

## 🔥 What to expect
## What to expect

Watch as Codeflash:
1. Analyzes your code's intent
2. Generates and runs test cases to understand behavior
3. Proposes multiple optimization strategies
4. Benchmarks each strategy for speed
5. Verifies correctness with regression tests
6. Creates a Pull Request with the fastest correct implementation
7. Shows impressive speedups (up to 90x in some cases!)
1. Discovers all language configs in the project
2. Analyzes your code's intent
3. Generates and runs test cases to understand behavior
4. Proposes multiple optimization strategies
5. Benchmarks each strategy for speed
6. Verifies correctness with regression tests
7. Creates a Pull Request with the fastest correct implementation


## 🤝 Need Help?
## Need Help?

Join our [Discord community](https://www.codeflash.ai/discord) for support and to connect with other developers who love fast code.

## Contributing

**Please don't** open Pull Requests on this repo with the optimizations you found. We want to keep this project unoptimized for future users to experience Codeflash.

Want to contribute? Here's how:
1. Fork the repository
2. Create a new branch for your changes
3. Add code that demonstrates CodeFlash's optimization capabilities
4. Submit a pull request with a clear description of your changes

We welcome bug reports and feature requests through Github's issues system.
Want to contribute? Add code that demonstrates Codeflash's optimization capabilities across any supported language.

---

Never ship slow code again. Happy optimizing! ⚡

Never ship slow code again. Happy optimizing!
25 changes: 25 additions & 0 deletions java/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.optimizeme</groupId>
<artifactId>optimizeme-java</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>

<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
47 changes: 47 additions & 0 deletions java/src/main/java/com/optimizeme/CollectionUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.optimizeme;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class CollectionUtils {

public static <T extends Comparable<T>> List<T> mergeSorted(List<T> a, List<T> b) {
List<T> result = new ArrayList<>(a.size() + b.size());
int i = 0, j = 0;
while (i < a.size() && j < b.size()) {
if (a.get(i).compareTo(b.get(j)) <= 0) {
result.add(a.get(i++));
} else {
result.add(b.get(j++));
}
}
while (i < a.size()) {
result.add(a.get(i++));
}
while (j < b.size()) {
result.add(b.get(j++));
}
return result;
}

public static class FrequencyCounter<T> {
private final Map<T, Integer> counts = new HashMap<>();

public void add(T item) {
counts.merge(item, 1, Integer::sum);
}

public int getCount(T item) {
return counts.getOrDefault(item, 0);
}

public T mostFrequent() {
return counts.entrySet().stream()
.max(Map.Entry.comparingByValue())
.map(Map.Entry::getKey)
.orElse(null);
}
}
}
53 changes: 53 additions & 0 deletions java/src/main/java/com/optimizeme/StringProcessor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.optimizeme;

public class StringProcessor {

public static String reverseWords(String sentence) {
if (sentence == null) {
return null;
}
if (sentence.isEmpty()) {
return "";
}
String[] words = sentence.trim().split("\\s+");
StringBuilder sb = new StringBuilder();
for (int i = words.length - 1; i >= 0; i--) {
sb.append(words[i]);
if (i > 0) {
sb.append(" ");
}
}
return sb.toString();
}

public static int countVowels(String text) {
if (text == null) {
return 0;
}
int count = 0;
for (char c : text.toCharArray()) {
char lower = Character.toLowerCase(c);
if (lower == 'a' || lower == 'e' || lower == 'i' || lower == 'o' || lower == 'u') {
count++;
}
}
return count;
}

public static boolean isPalindrome(String text) {
if (text == null) {
return false;
}
String cleaned = text.toLowerCase().replaceAll("[^a-z0-9]", "");
int left = 0;
int right = cleaned.length() - 1;
while (left < right) {
if (cleaned.charAt(left) != cleaned.charAt(right)) {
return false;
}
left++;
right--;
}
return true;
}
}
39 changes: 39 additions & 0 deletions java/src/test/java/com/optimizeme/CollectionUtilsTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.optimizeme;

import org.junit.Test;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import static org.junit.Assert.assertEquals;

public class CollectionUtilsTest {

@Test
public void testMergeSortedIntegers() {
List<Integer> a = Arrays.asList(1, 3, 5);
List<Integer> b = Arrays.asList(2, 4, 6);
List<Integer> expected = Arrays.asList(1, 2, 3, 4, 5, 6);
assertEquals(expected, CollectionUtils.mergeSorted(a, b));
}

@Test
public void testMergeSortedEmptyList() {
List<Integer> a = Collections.emptyList();
List<Integer> b = Arrays.asList(1, 2, 3);
List<Integer> expected = Arrays.asList(1, 2, 3);
assertEquals(expected, CollectionUtils.mergeSorted(a, b));
}

@Test
public void testFrequencyCounterBasic() {
CollectionUtils.FrequencyCounter<String> counter = new CollectionUtils.FrequencyCounter<>();
counter.add("a");
counter.add("a");
counter.add("a");
counter.add("b");
assertEquals(3, counter.getCount("a"));
assertEquals("a", counter.mostFrequent());
}
}
30 changes: 30 additions & 0 deletions java/src/test/java/com/optimizeme/StringProcessorTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.optimizeme;

import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

public class StringProcessorTest {

@Test
public void testReverseWords() {
assertEquals("world hello", StringProcessor.reverseWords("hello world"));
}

@Test
public void testReverseWordsNull() {
assertNull(StringProcessor.reverseWords(null));
}

@Test
public void testCountVowels() {
assertEquals(3, StringProcessor.countVowels("Hello World"));
}

@Test
public void testIsPalindrome() {
assertTrue(StringProcessor.isPalindrome("A man a plan a canal Panama"));
}
}
1 change: 1 addition & 0 deletions js/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
Loading
Loading