You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Codeflash follows a "generate and verify" approach to optimize code. It uses LLMs to generate optimizations, then it rigorously verifies if those optimizations are indeed
11
11
faster and if they have the same behavior. The basic unit of optimization is a function—Codeflash tries to speed up the function, and tries to ensure that it still behaves the same way. This way if you merge the optimized code, it simply runs faster without breaking any functionality.
12
12
13
-
Codeflash supports **Python**, **JavaScript**, and **TypeScript** projects.
13
+
Codeflash supports **Python**, **JavaScript**, **TypeScript**, and **Java** projects.
14
14
15
15
## Analysis of your code
16
16
17
17
Codeflash scans your codebase to identify all available functions. It locates existing unit tests in your projects and maps which functions they test. When optimizing a function, Codeflash runs these discovered tests to verify nothing has broken.
18
18
19
-
For Python, code analysis uses `libcst` and `jedi`. For JavaScript/TypeScript, it uses `tree-sitter` for AST parsing.
19
+
For Python, code analysis uses `libcst` and `jedi`. For JavaScript/TypeScript and Java, it uses `tree-sitter` for AST parsing.
20
20
21
21
#### What kind of functions can Codeflash optimize?
22
22
@@ -25,7 +25,7 @@ Codeflash supports optimizing async functions in all supported languages.
25
25
26
26
#### Test Discovery
27
27
28
-
Codeflash discovers tests that directly call the target function in their test body. For Python, it finds pytest and unittest tests. For JavaScript/TypeScript, it finds Jest and Vitest test files.
28
+
Codeflash discovers tests that directly call the target function in their test body. For Python, it finds pytest and unittest tests. For JavaScript/TypeScript, it finds Jest and Vitest test files. For Java, it finds JUnit 5, JUnit 4, and TestNG test classes.
29
29
30
30
To discover tests that indirectly call the function, you can use the Codeflash Tracer. The Tracer analyzes your test suite and identifies all tests that eventually call a function.
31
31
@@ -54,12 +54,12 @@ We recommend manually reviewing the optimized code since there might be importan
54
54
55
55
Codeflash generates two types of tests:
56
56
57
-
-**LLM Generated tests** - Codeflash uses LLMs to create several regression test cases that cover typical function usage, edge cases, and large-scale inputs to verify both correctness and performance. This works for Python, JavaScript, and TypeScript.
57
+
-**LLM Generated tests** - Codeflash uses LLMs to create several regression test cases that cover typical function usage, edge cases, and large-scale inputs to verify both correctness and performance. This works for Python, JavaScript, TypeScript, and Java.
58
58
-**Concolic coverage tests** - Codeflash uses state-of-the-art concolic testing with an SMT Solver (a theorem prover) to explore execution paths and generate function arguments. This aims to maximize code coverage for the function being optimized. Currently, this feature only supports Python (pytest).
59
59
60
60
## Code Execution
61
61
62
-
Codeflash runs tests for the target function on your machine. For Python, it uses pytest or unittest. For JavaScript/TypeScript, it uses Jest or Vitest. Running on your machine ensures access to your environment and dependencies, and provides accurate performance measurements since runtime varies by system.
62
+
Codeflash runs tests for the target function on your machine. For Python, it uses pytest or unittest. For JavaScript/TypeScript, it uses Jest or Vitest. For Java, it uses Maven Surefire or Gradle's test task. Running on your machine ensures access to your environment and dependencies, and provides accurate performance measurements since runtime varies by system.
Copy file name to clipboardExpand all lines: docs/getting-started/java-installation.mdx
+66-6Lines changed: 66 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -47,18 +47,72 @@ uv tool install codeflash
47
47
```
48
48
49
49
</Step>
50
-
<Steptitle="Initialize your project">
50
+
<Steptitle="Authenticate with Codeflash">
51
+
52
+
Codeflash uses cloud-hosted AI models. You need to authenticate before running any commands.
53
+
54
+
**Option A: Browser login (recommended)**
55
+
56
+
```bash
57
+
codeflash auth login
58
+
```
59
+
60
+
This opens your browser to sign in with your GitHub account. Your API key is saved automatically to your shell profile.
61
+
62
+
If you're on a remote server without a browser, a URL will be displayed that you can open on any device.
63
+
64
+
**Option B: API key**
65
+
66
+
1. Visit the [Codeflash Web App](https://app.codeflash.ai/) and sign up with your GitHub account (free tier available)
67
+
2. Navigate to the [API Key](https://app.codeflash.ai/app/apikeys) page to generate your key
68
+
3. Set it as an environment variable:
69
+
70
+
```bash
71
+
export CODEFLASH_API_KEY="your-api-key-here"
72
+
```
73
+
74
+
Add this to your shell profile (`~/.bashrc`, `~/.zshrc`) so it persists across sessions.
75
+
76
+
<Info>
77
+
If you skip this step, `codeflash init` will prompt you to authenticate interactively.
78
+
</Info>
79
+
80
+
</Step>
81
+
<Steptitle="Initialize your project (recommended)">
51
82
52
83
Navigate to your Java project root (where `pom.xml` or `build.gradle` is) and run:
53
84
54
85
```bash
55
86
codeflash init
56
87
```
57
88
58
-
This will:
59
-
- Detect your build tool (Maven/Gradle)
60
-
- Find your source and test directories
61
-
- Write Codeflash configuration to your `pom.xml` properties (Maven) or `gradle.properties` (Gradle)
89
+
The init command will:
90
+
1.**Auto-detect your project** — find your build tool, source root (e.g., `src/main/java`), test root (e.g., `src/test/java`), and test framework
91
+
2.**Confirm settings** — show the detected values and ask if you want to change anything
92
+
3.**Configure formatter** — let you set up a code formatter (e.g., Spotless, google-java-format)
93
+
4.**Install GitHub App** — offer to set up the [Codeflash GitHub App](https://github.com/apps/codeflash-ai/installations/select_target) for automatic PR creation (see next step)
94
+
5.**Install GitHub Actions** — offer to add a CI workflow for automated optimization on PRs
95
+
96
+
Only non-default settings are written to your `pom.xml` properties (Maven) or `gradle.properties` (Gradle). For standard layouts, no config changes are needed.
97
+
98
+
<Info>
99
+
**Can I skip init?** Yes. For standard Maven/Gradle projects, Codeflash auto-detects your project structure from `pom.xml` or `build.gradle` at runtime. If you're already authenticated and your project uses a standard layout (`src/main/java`, `src/test/java`), you can skip straight to optimizing.
100
+
101
+
Init is recommended because it also sets up the GitHub App and Actions workflow, and lets you override paths for non-standard project layouts (e.g., multi-module projects where source is under `client/src/`).
102
+
</Info>
103
+
104
+
</Step>
105
+
<Steptitle="Install the Codeflash GitHub App (recommended)">
106
+
107
+
To have Codeflash create pull requests with optimizations automatically, install the GitHub App:
Select the repositories you want Codeflash to optimize. This allows the codeflash-ai bot to open PRs with optimization suggestions in your repository.
112
+
113
+
<Info>
114
+
If you prefer to try Codeflash locally first, you can skip this step and use the `--no-pr` flag to apply optimizations directly to your local files (see next step).
If you installed the GitHub App, Codeflash will create a pull request with the optimization. If you haven't installed the app yet, or prefer to review changes locally first, add `--no-pr`:
The `-cp` approach works with any project after `mvn compile` or `gradle build`. The `-jar` approach requires your project to produce an executable JAR with a `Main-Class` entry in the manifest — this is not the default Maven behavior.
239
+
238
240
Codeflash will run your program twice (once for profiling, once for argument capture), generate JUnit replay tests, then optimize the most impactful functions.
239
241
240
242
2.**Long-running programs**
241
243
242
244
For servers, benchmarks, or programs that don't terminate on their own, use `--timeout` to limit each tracing stage:
0 commit comments