Prerequisites
Before installing Codeflash, ensure you have:- Java 11 or above installed
- Maven or Gradle as your build tool
- A Java project with source code under a standard directory layout
- Unit tests (JUnit 5 or JUnit 4) — Codeflash uses them alongside traced replay tests to verify correctness
Initialize your project
Navigate to your Java project root (where This will:
pom.xml or build.gradle is) and run:- Detect your build tool (Maven/Gradle)
- Find your source and test directories
- Create a
codeflash.tomlconfiguration file
Run your first optimization
Trace and optimize a running Java program:Or with Maven:Codeflash will:
- Profile your program using JFR (Java Flight Recorder)
- Capture method arguments using a bytecode instrumentation agent
- Generate JUnit replay tests from the captured data
- Rank functions by performance impact
- Optimize the most impactful functions
How it works
Codeflash uses a two-stage tracing approach for Java:- Stage 1 — JFR Profiling: Runs your program with Java Flight Recorder enabled to collect accurate method-level CPU profiling data. JFR has ~1% overhead and doesn’t affect JIT compilation.
- Stage 2 — Argument Capture: Runs your program again with a bytecode instrumentation agent that captures method arguments using Kryo serialization. Arguments are stored in an SQLite database.
Your program runs twice — once for profiling, once for argument capture. This separation ensures profiling data isn’t distorted by serialization overhead.
Supported build tools
| Build Tool | Detection | Test Execution |
|---|---|---|
| Maven | pom.xml | Maven Surefire plugin |
| Gradle | build.gradle / build.gradle.kts | Gradle test task |
Supported test frameworks
| Framework | Support Level |
|---|---|
| JUnit 5 | Full support (default) |
| JUnit 4 | Full support |
| TestNG | Basic support |