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
Copy file name to clipboardExpand all lines: docs/codeflash-concepts/how-codeflash-works.mdx
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -57,7 +57,7 @@ Codeflash runs tests for the target function using either pytest or unittest fra
57
57
58
58
#### Performance benchmarking
59
59
60
-
Codeflash implements [several techniques](/codeflash-concepts/benchmarking.md) to measure code performance accurately. In particular, it runs multiple iterations of the code in a loop to determine the best performance with the minimum runtime. Codeflash compares the performance of the original code against the optimization, requiring at least a 10% speed improvement before considering it to be faster. This approach eliminates most runtime measurement variability, even on noisy CI systems and virtual machines. The final runtime Codeflash reports is the minimum total time it took to run all the test cases.
60
+
Codeflash implements [several techniques](/codeflash-concepts/benchmarking) to measure code performance accurately. In particular, it runs multiple iterations of the code in a loop to determine the best performance with the minimum runtime. Codeflash compares the performance of the original code against the optimization, requiring at least a 10% speed improvement before considering it to be faster. This approach eliminates most runtime measurement variability, even on noisy CI systems and virtual machines. The final runtime Codeflash reports is the minimum total time it took to run all the test cases.
Copy file name to clipboardExpand all lines: docs/getting-started/local-installation.mdx
+42-54Lines changed: 42 additions & 54 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,31 +6,32 @@ icon: "download"
6
6
7
7
Codeflash is installed and configured on a per-project basis.
8
8
9
-
You can install Codeflash locally for a project by running the following command in the project's virtual environment:
10
-
11
9
### Prerequisites
12
10
13
11
Before installing Codeflash, ensure you have:
14
12
15
13
1.**Python 3.9 or above** installed
16
14
2.**A Python project** with a virtual environment
17
15
3.**Project dependencies installed** in your virtual environment
18
-
4.**Tests** (optional) for your code (Codeflash uses tests to verify optimizations)
16
+
17
+
Good to have (optional):
18
+
1.**Unit Tests** that Codeflash uses to ensure correctness of the optimizations
19
19
20
20
<Warning>
21
21
**Virtual Environment Required**
22
22
23
23
Always install Codeflash in your project's virtual environment, not globally. Make sure your virtual environment is activated before proceeding.
24
24
25
25
```bash
26
-
# Example: Activate your virtual environment
27
26
source venv/bin/activate # On Linux/Mac
28
27
# or
29
-
#venv\Scripts\activate # On Windows
28
+
venv\Scripts\activate # On Windows
30
29
```
31
30
</Warning>
32
31
<Steps>
33
32
<Steptitle="Install Codeflash">
33
+
34
+
You can install Codeflash locally for a project by running the following command in the project's virtual environment:
34
35
```bash
35
36
pip install codeflash
36
37
```
@@ -39,48 +40,39 @@ pip install codeflash
39
40
**Codeflash is a Development Dependency**
40
41
41
42
We recommend installing Codeflash as a development dependency.
42
-
It doesn't need to be installed as part of your package requirements.
43
-
Codeflash is intended to be used locally and as part of development workflows such as CI.
43
+
Codeflash is intended to be used in development workflows locally and as part of CI.
44
+
Try to always use the latest version of Codeflash as it improves quickly.
44
45
45
46
<CodeGroup>
46
-
```toml Poetry
47
-
[tool.poetry.dependencies.dev]
48
-
codeflash = "^latest"
49
-
```
50
-
51
47
```bash uv
52
48
uv add --dev codeflash
53
49
```
54
50
55
-
```bashpip
56
-
pip install --dev codeflash
51
+
```bashpoetry
52
+
poetry add codeflash@latest --group dev
57
53
```
58
54
</CodeGroup>
59
55
</Tip>
60
56
</Step>
61
57
62
58
<Steptitle="Generate a Codeflash API Key">
63
-
Codeflash uses cloud-hosted AI models to optimize your code. You'll need an API key to use it.
59
+
Codeflash uses cloud-hosted AI models and integrations with GitHub. You'll need an API key to authorize your access.
64
60
65
-
1. Visit the [Codeflash Web App](https://app.codeflash.ai/)
61
+
1. Visit the [Codeflash Web App](https://app.codeflash.ai/)
66
62
2. Sign up with your GitHub account (free)
67
63
3. Navigate to the [API Key](https://app.codeflash.ai/app/apikeys) page to generate your API key
68
64
69
65
<Note>
70
66
**Free Tier Available**
71
67
72
-
Codeflash offers a **free tier** with a limited number of optimizations per month. Perfect for trying it out or small projects!
68
+
Codeflash offers a **free tier** with a limited number of optimizations. Perfect for trying it out on small projects!
73
69
</Note>
74
70
</Step>
75
71
76
72
<Steptitle="Run Automatic Configuration">
77
73
Navigate to your project's root directory (where your `pyproject.toml` file is or should be) and run:
78
74
79
75
```bash
80
-
# Make sure you're in your project root
81
-
cd /path/to/your/project
82
-
83
-
# Run the initialization
84
76
codeflash init
85
77
```
86
78
@@ -89,30 +81,31 @@ If you don't have a pyproject.toml file yet, the codeflash init command will ask
89
81
<Info>
90
82
**What's pyproject.toml?**
91
83
92
-
`pyproject.toml` is a configuration file that is used to specify build tool settings for Python projects.
93
-
pyproject.toml is the modern replacement for setup.py and requirements.txt files.
94
-
It's the new standard for Python package metadata.
84
+
`pyproject.toml` is a configuration file that is used to specify build and tool settings for Python projects.
85
+
`pyproject.toml` is the modern replacement for setup.py and requirements.txt files.
95
86
</Info>
96
87
97
88
When running `codeflash init`, you will see the following prompts:
98
89
99
90
```text
100
-
1. Enter your Codeflash API key:
101
-
2. Which Python module do you want me to optimize going forward? (e.g. my_module)
102
-
3. Where are your tests located? (e.g. tests/)
103
-
4. Which test framework do you use? (pytest/unittest)
91
+
1. Enter your Codeflash API key:
92
+
2. Install the GitHub app.
93
+
3. Which Python module do you want me to optimize going forward? (e.g. my_module)
94
+
4. Where are your tests located? (e.g. tests/)
95
+
5. Which test framework do you use? (pytest/unittest)
96
+
6. Install GitHub actions for Continuous optimization?
104
97
```
105
98
</Step>
106
99
</Steps>
107
100
108
-
After you have answered these questions, Codeflash will be configured for your project.
109
-
The configuration will be saved in the `pyproject.toml` file in the root directory of your project.
110
-
To understand the configuration options, and set more advanced options, see the [Configuration](/configuration) page.
101
+
After you have answered these questions, the Codeflash configuration will be saved in the `pyproject.toml` file.
102
+
To understand the configuration options, and set more advanced options, see the [Manual Configuration](/configuration) page.
111
103
112
104
### Step 4: Install the Codeflash GitHub App
113
105
114
106
{/* TODO: Justify to users Why we need the user to install Github App even in local Installation or local optimization? */}
115
-
Finally, if you have not done so already, Codeflash will ask you to install the Github App in your repository. The Codeflash GitHub App allows access to your repository to the codeflash-ai bot to open PRs, review code, and provide optimization suggestions.
107
+
Finally, if you have not done so already, Codeflash will ask you to install the GitHub App in your repository.
108
+
The Codeflash GitHub App allows access to your repository to the codeflash-ai bot to open PRs, review code, and provide optimization suggestions.
116
109
117
110
Please [install the Codeflash GitHub
118
111
app](https://github.com/apps/codeflash-ai/installations/select_target) by choosing the repository you want to install
@@ -128,38 +121,37 @@ Once configured, you can start optimizing your code immediately:
**Pro tip**: Start with a single function to see how Codeflash works before running it on your entire codebase.
137
-
</Tip>
138
128
</Tab>
139
129
140
-
<Tabtitle="Example Project">
141
-
<Cardtitle="🚀 Try Our Example Repository"icon="github"href="https://github.com/codeflash-ai/optimize-me">
142
-
Want to see Codeflash in action? Check out our **optimize-me** repository with real examples.
130
+
<Tabtitle="Optimize Example Project">
131
+
<Cardtitle="🚀 Try optimizing our example repository"icon="github"href="https://github.com/codeflash-ai/optimize-me">
132
+
Want to see Codeflash in action and don't know what code to optimize? Check out our **optimize-me** repository with code ready to optimize.
143
133
144
134
**What's included:**
145
135
- Sample Python code with performance issues
146
136
- Tests for verification
147
137
- Pre-configured `pyproject.toml`
148
-
- Before/after optimization examples in PRs
149
138
</Card>
150
139
151
140
<Steps>
152
-
<Steptitle="Clone the Repository">
141
+
<Steptitle="Fork the Repository">
142
+
Fork the [optimize-me](https://github.com/codeflash-ai/optimize-me) 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.
Codeflash is a powerful tool; here are our recommendations based on how the Codeflash team and our customers use Codeflash.
10
10
11
-
Codeflash is a powerful tool; here are our recommendations based on how the Codeflash team uses Codeflash.
11
+
### Install the GitHub App and actions workflow
12
12
13
-
### Install the Github App and actions workflow
14
-
15
-
After you install Codeflash on an actively developed project, [installing the GitHub App](getting-started/codeflash-github-actions) and setting up the
16
-
GitHub Actions workflow will automatically optimize your code whenever new pull requests are opened. This ensures you get the best version of any changes you make to your code without any extra effort. We find that PRs are also the best time to review these changes, because the code is fresh in your mind.
13
+
After you install Codeflash on an actively developed project, [installing the GitHub Actions](optimizing-with-codeflash/codeflash-github-actions) will automatically optimize your code whenever new pull requests are opened. This ensures you get the best version of any changes you make to your code without any extra effort. We find that PRs are also the best time to review these changes, because the code is fresh in your mind.
17
14
18
15
### Find and optimize entire scripts with the Codeflash Tracer
19
16
20
17
Find the best results by running [Codeflash Optimize](optimizing-with-codeflash/trace-and-optimize) on your script to optimize it.
21
18
This internally runs a profiler, captures inputs to all the functions your script calls, and uses those inputs to create Replay tests and benchmarks.
22
19
The optimizations you get with this method, show you how much faster your workflow will get plus guarantee that your workflow won't break if you merge in the optimizations.
23
20
24
-
###
25
21
26
22
### Find optimizations on your whole codebase with `codeflash --all`
27
23
28
24
If you have a lot of existing code, run [`codeflash --all`](optimizing-with-codeflash/codeflash-all) to discover and fix any
29
25
slow code in your project. Codeflash will open new pull requests for any optimizations it finds, and you can review and merge them at your own pace.
30
26
27
+
It is first recommended to trace your tests to achieve higher quality optimizations with this approach
0 commit comments