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
+39-54Lines changed: 39 additions & 54 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,31 +6,29 @@ 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)
19
16
20
17
<Warning>
21
18
**Virtual Environment Required**
22
19
23
20
Always install Codeflash in your project's virtual environment, not globally. Make sure your virtual environment is activated before proceeding.
24
21
25
22
```bash
26
-
# Example: Activate your virtual environment
27
23
source venv/bin/activate # On Linux/Mac
28
24
# or
29
-
#venv\Scripts\activate # On Windows
25
+
venv\Scripts\activate # On Windows
30
26
```
31
27
</Warning>
32
28
<Steps>
33
29
<Steptitle="Install Codeflash">
30
+
31
+
You can install Codeflash locally for a project by running the following command in the project's virtual environment:
34
32
```bash
35
33
pip install codeflash
36
34
```
@@ -39,48 +37,39 @@ pip install codeflash
39
37
**Codeflash is a Development Dependency**
40
38
41
39
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.
40
+
Codeflash is intended to be used in development workflows locally and as part of CI.
41
+
Try to always use the latest version of Codeflash as it improves quickly.
44
42
45
43
<CodeGroup>
46
-
```toml Poetry
47
-
[tool.poetry.dependencies.dev]
48
-
codeflash = "^latest"
49
-
```
50
-
51
44
```bash uv
52
45
uv add --dev codeflash
53
46
```
54
47
55
-
```bashpip
56
-
pip install --dev codeflash
48
+
```bashpoetry
49
+
poetry add codeflash@latest --group dev
57
50
```
58
51
</CodeGroup>
59
52
</Tip>
60
53
</Step>
61
54
62
55
<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.
56
+
Codeflash uses cloud-hosted AI models and integrations with GitHub. You'll need an API key to authorize your accesss.
64
57
65
-
1. Visit the [Codeflash Web App](https://app.codeflash.ai/)
58
+
1. Visit the [Codeflash Web App](https://app.codeflash.ai/)
66
59
2. Sign up with your GitHub account (free)
67
60
3. Navigate to the [API Key](https://app.codeflash.ai/app/apikeys) page to generate your API key
68
61
69
62
<Note>
70
63
**Free Tier Available**
71
64
72
-
Codeflash offers a **free tier** with a limited number of optimizations per month. Perfect for trying it out or small projects!
65
+
Codeflash offers a **free tier** with a limited number of optimizations. Perfect for trying it out on small projects!
73
66
</Note>
74
67
</Step>
75
68
76
69
<Steptitle="Run Automatic Configuration">
77
70
Navigate to your project's root directory (where your `pyproject.toml` file is or should be) and run:
78
71
79
72
```bash
80
-
# Make sure you're in your project root
81
-
cd /path/to/your/project
82
-
83
-
# Run the initialization
84
73
codeflash init
85
74
```
86
75
@@ -89,30 +78,31 @@ If you don't have a pyproject.toml file yet, the codeflash init command will ask
89
78
<Info>
90
79
**What's pyproject.toml?**
91
80
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.
81
+
`pyproject.toml` is a configuration file that is used to specify build and tool settings for Python projects.
82
+
`pyproject.toml` is the modern replacement for setup.py and requirements.txt files.
95
83
</Info>
96
84
97
85
When running `codeflash init`, you will see the following prompts:
98
86
99
87
```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)
88
+
1. Enter your Codeflash API key:
89
+
2. Install the GitHub app.
90
+
3. Which Python module do you want me to optimize going forward? (e.g. my_module)
91
+
4. Where are your tests located? (e.g. tests/)
92
+
5. Which test framework do you use? (pytest/unittest)
93
+
6. Install GitHub actions for Continuous optimization?
104
94
```
105
95
</Step>
106
96
</Steps>
107
97
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.
98
+
After you have answered these questions, the Codeflash configuration will be saved in the `pyproject.toml` file.
99
+
To understand the configuration options, and set more advanced options, see the [Manual Configuration](/configuration) page.
111
100
112
101
### Step 4: Install the Codeflash GitHub App
113
102
114
103
{/* 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.
104
+
Finally, if you have not done so already, Codeflash will ask you to install the GitHub App in your repository.
105
+
The Codeflash GitHub App allows access to your repository to the codeflash-ai bot to open PRs, review code, and provide optimization suggestions.
116
106
117
107
Please [install the Codeflash GitHub
118
108
app](https://github.com/apps/codeflash-ai/installations/select_target) by choosing the repository you want to install
@@ -128,38 +118,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
125
</Tab>
139
126
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.
127
+
<Tabtitle="Optimize Example Project">
128
+
<Cardtitle="🚀 Try optimizing our example repository"icon="github"href="https://github.com/codeflash-ai/optimize-me">
129
+
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
130
144
131
**What's included:**
145
132
- Sample Python code with performance issues
146
133
- Tests for verification
147
134
- Pre-configured `pyproject.toml`
148
-
- Before/after optimization examples in PRs
149
135
</Card>
150
136
151
137
<Steps>
152
-
<Steptitle="Clone the Repository">
138
+
<Steptitle="Fork the Repository">
139
+
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