update docs and sidebar index

This commit is contained in:
Sarthak Agarwal 2026-03-05 01:59:56 +05:30
parent f0e4e5326d
commit 6b644faf25
8 changed files with 218 additions and 52 deletions

View file

@ -2,7 +2,7 @@
title: "How Codeflash Measures Code Runtime on GPUs"
description: "Learn how Codeflash accurately measures code performance on GPUs"
icon: "microchip"
sidebarTitle: "GPU Benchmarking"
sidebarTitle: "GPU Benchmarking (Python)"
keywords: ["benchmarking", "performance", "timing", "measurement", "runtime", "noise reduction", "GPU", "MPS"]
---

View file

@ -2,7 +2,7 @@
title: "JavaScript / TypeScript Configuration"
description: "Configure Codeflash for JavaScript and TypeScript projects using package.json"
icon: "js"
sidebarTitle: "JavaScript / TypeScript"
sidebarTitle: "JS / TS (package.json)"
keywords:
[
"configuration",
@ -66,7 +66,7 @@ You can always override any auto-detected value in the `"codeflash"` section.
## Optional Options
- `testRunner`: Test framework to use. Auto-detected from your dependencies. Supported values: `"jest"`, `"vitest"`.
- `testRunner`: Test framework to use. Auto-detected from your dependencies. Supported values: `"jest"`, `"vitest"`, `"mocha"`.
- `formatterCmds`: Formatter commands. `$file` refers to the file being optimized. Disable with `["disabled"]`.
- **Prettier**: `["prettier --write $file"]`
- **ESLint + Prettier**: `["eslint --fix $file", "prettier --write $file"]`
@ -102,6 +102,7 @@ No separate configuration is needed for TypeScript vs JavaScript.
|-----------|-------------------|-------|
| **Jest** | `jest` in dependencies | Default for most projects |
| **Vitest** | `vitest` in dependencies | ESM-native support |
| **Mocha** | `mocha` in dependencies | Uses `node:assert/strict`, zero extra deps |
<Info>
**Functions must be exported** to be optimizable. Codeflash uses tree-sitter AST analysis to discover functions and check export status. Supported export patterns:
@ -198,6 +199,44 @@ my-app/
}
```
### Project with scattered test folders
If your tests are spread across multiple directories (e.g., `test/` at root and `__tests__/` inside `src/`), set `testsRoot` to the common ancestor:
```text
my-app/
|- src/
| |- utils/
| | |- __tests__/
| | | |- utils.test.js
| | |- helpers.js
| |- components/
| | |- __tests__/
| | | |- Button.test.jsx
| | |- Button.jsx
|- test/
| |- integration.test.js
|- package.json
```
```json
{
"name": "my-app",
"codeflash": {
"moduleRoot": "src",
"testsRoot": "."
}
}
```
<Info>
**`testsRoot` is a single path.** Codeflash recursively searches for `*.test.js`, `*.spec.js`, and `__tests__/**/*.js` files under this directory. Setting it to `"."` (project root) discovers tests everywhere, including co-located `__tests__/` folders inside `src/`.
</Info>
<Warning>
**Monorepos with per-package tests:** Don't set `testsRoot` to the monorepo root. Instead, run codeflash from each package directory with its own config. Each package's `testsRoot` is relative to that package.
</Warning>
### CommonJS library with no separate test directory
```text
@ -218,3 +257,115 @@ my-lib/
}
}
```
## Manual Configuration (without `codeflash init`)
If you prefer to configure manually or `codeflash init` doesn't detect your project correctly, add the `"codeflash"` key directly to your `package.json`:
```json
{
"name": "my-project",
"codeflash": {
"moduleRoot": "src",
"testsRoot": "tests",
"testRunner": "vitest",
"formatterCmds": ["prettier --write $file"],
"ignorePaths": ["src/generated/", "src/vendor/"]
}
}
```
### Step-by-step
1. **Set `moduleRoot`** — the directory containing your source code. Only files under this path are discovered for optimization.
2. **Set `testsRoot`** — the directory containing your tests. Codeflash searches recursively for `*.test.js`, `*.spec.js`, and `__tests__/**/*.js` files.
3. **Set `testRunner`** (optional) — `"jest"`, `"vitest"`, or `"mocha"`. Auto-detected from `devDependencies` if omitted.
4. **Set `formatterCmds`** (optional) — commands to format optimized code. `$file` is replaced with the file path. Use `["disabled"]` to skip formatting.
5. **Set `ignorePaths`** (optional) — directories to exclude from optimization (relative to `moduleRoot`).
### CLI flag overrides
All config values can be overridden via CLI flags:
```bash
# Override moduleRoot and testsRoot for a single run
codeflash --file src/utils.ts --function myFunc \
--module-root src \
--tests-root test \
--no-pr
# Specify a directory to optimize (within moduleRoot)
codeflash --all src/utils/
```
## FAQ
<AccordionGroup>
<Accordion title="Will codeflash handle test files scattered throughout a package?">
Yes, as long as `testsRoot` is set to a common ancestor directory. Codeflash recursively searches for `*.test.js`, `*.spec.js`, and `__tests__/**/*.js` under `testsRoot`.
For co-located tests (test files next to source files), set `testsRoot` to the same value as `moduleRoot`:
```json
{
"codeflash": {
"moduleRoot": "src",
"testsRoot": "src"
}
}
```
For tests in multiple directories, set `testsRoot` to `"."` (project root) to discover them all.
**Note:** `testsRoot` accepts a single path. For monorepos, run codeflash from each package directory with its own config rather than trying to cover all packages from the root.
</Accordion>
<Accordion title="Do I need to add one test folder at a time?">
No. Codeflash recursively searches `testsRoot`, so a single path covers all nested test directories. For example, `"testsRoot": "."` discovers tests anywhere in the project:
- `test/unit/*.test.js`
- `src/components/__tests__/Button.test.tsx`
- `lib/utils.spec.js`
All of these are found with a single `testsRoot` setting.
</Accordion>
<Accordion title="How does codeflash find existing tests for a function?">
Codeflash matches tests to functions by:
1. Scanning all test files under `testsRoot` (matching `*.test.*`, `*.spec.*`, `__tests__/**/*`)
2. Parsing imports in each test file using tree-sitter
3. Matching imported function names to the target function
If a test file imports `myFunction` from `./utils`, it's considered a test for `myFunction`.
</Accordion>
<Accordion title="What if codeflash init detects the wrong values?">
Override any value in `package.json` under the `"codeflash"` key. The most common overrides:
```json
{
"codeflash": {
"moduleRoot": "src/lib",
"testsRoot": ".",
"testRunner": "mocha"
}
}
```
Or use CLI flags for one-off overrides: `--module-root`, `--tests-root`.
</Accordion>
<Accordion title="Can I use codeflash with a standalone codeflash.yaml?">
For internal testing and development, codeflash also reads `codeflash.yaml` files. This is useful when you don't want to modify `package.json`:
```yaml
module_root: "src"
tests_root: "test"
test_framework: "vitest"
formatter_cmds: []
```
Place this in the project root. The `package.json` config takes precedence if both exist.
</Accordion>
</AccordionGroup>

View file

@ -2,7 +2,7 @@
title: "Python Configuration"
description: "Configure Codeflash for Python projects using pyproject.toml"
icon: "python"
sidebarTitle: "Python"
sidebarTitle: "Python (pyproject.toml)"
keywords:
[
"configuration",

View file

@ -19,43 +19,37 @@
"tab": "Documentation",
"groups": [
{
"group": "🏠 Overview",
"group": "Overview",
"pages": ["index"]
},
{
"group": "🚀 Quickstart",
"group": "Getting Started",
"pages": [
"getting-started/local-installation",
"getting-started/javascript-installation"
]
},
{
"group": "⚡ Optimizing with Codeflash",
"group": "Using Codeflash",
"pages": [
"optimizing-with-codeflash/one-function",
"optimizing-with-codeflash/codeflash-all",
"optimizing-with-codeflash/trace-and-optimize",
"optimizing-with-codeflash/codeflash-all"
]
},
{
"group": "✨ Continuous Optimization",
"pages": [
"optimizing-with-codeflash/codeflash-github-actions",
"optimizing-with-codeflash/benchmarking",
"optimizing-with-codeflash/review-optimizations"
]
},
{
"group": "🛠 IDE Extension",
"group": "Configuration",
"pages": [
"editor-plugins/vscode/index",
"editor-plugins/vscode/features",
"editor-plugins/vscode/configuration",
"editor-plugins/vscode/troubleshooting"
"configuration/python",
"configuration/javascript",
"getting-the-best-out-of-codeflash"
]
},
{
"group": "🧠 Core Concepts",
"group": "Core Concepts",
"pages": [
"codeflash-concepts/how-codeflash-works",
"codeflash-concepts/benchmarking",
@ -64,8 +58,13 @@
]
},
{
"group": "⚙️ Configuration & Best Practices",
"pages": ["configuration", "getting-the-best-out-of-codeflash"]
"group": "IDE Extension",
"pages": [
"editor-plugins/vscode/index",
"editor-plugins/vscode/features",
"editor-plugins/vscode/configuration",
"editor-plugins/vscode/troubleshooting"
]
}
]
}

View file

@ -1,7 +1,8 @@
---
title: "JavaScript / TypeScript Installation"
description: "Install and configure Codeflash for your JavaScript/TypeScript project"
icon: "node-js"
icon: "js"
sidebarTitle: "JS / TS Setup"
keywords:
[
"installation",
@ -214,7 +215,11 @@ my-monorepo/
|-----------|--------|-------------------|
| **Jest** | Supported | `jest` in dependencies |
| **Vitest** | Supported | `vitest` in dependencies |
| **Mocha** | Coming soon | — |
| **Mocha** | Supported | `mocha` in dependencies |
<Info>
**Mocha projects** use `node:assert/strict` for generated tests (zero extra dependencies). Mocha's `describe`/`it` globals are used automatically — no imports needed.
</Info>
<Info>
**Functions must be exported** to be optimizable. Codeflash can only discover and optimize functions that are exported from their module (via `export`, `export default`, or `module.exports`).
@ -237,8 +242,8 @@ codeflash --file src/utils.ts --function processData --no-pr
codeflash --all
```
```bash Trace and optimize
codeflash optimize --jest
```bash Dry run (see what would be optimized)
codeflash --all --dry-run
```
</CodeGroup>

View file

@ -1,7 +1,8 @@
---
title: "Local Installation"
title: "Python Installation"
description: "Install and configure Codeflash for your Python project in minutes"
icon: "download"
icon: "python"
sidebarTitle: "Python Setup"
---
Codeflash is installed and configured on a per-project basis.

View file

@ -13,46 +13,56 @@ does not modify the system architecture of your code, but it tries to find the m
### Get Started
Pick your language to install and configure Codeflash:
<CardGroup cols={2}>
<Card title="Python Setup" icon="python" href="/getting-started/local-installation">
Install via pip, uv, or poetry
<Card title="Python" icon="python" href="/getting-started/local-installation">
Install via pip, uv, or poetry. Configure in `pyproject.toml`.
</Card>
<Card title="JavaScript / TypeScript Setup" icon="js" href="/getting-started/javascript-installation">
Install via npm, yarn, pnpm, or bun
<Card title="JavaScript / TypeScript" icon="js" href="/getting-started/javascript-installation">
Install via npm, yarn, pnpm, or bun. Configure in `package.json`. Supports Jest, Vitest, and Mocha.
</Card>
</CardGroup>
### How to use Codeflash
<CardGroup cols={1}>
<Card title="Optimize a Single Function" icon="bullseye" href="/optimizing-with-codeflash/one-function">
Target and optimize individual functions for maximum performance gains.
These commands work for both Python and JS/TS projects:
<CardGroup cols={2}>
<Card title="Optimize a Function" icon="bullseye" href="/optimizing-with-codeflash/one-function">
```bash
codeflash --file path/to/file --function my_function
```
</Card>
<Card title="Optimize Pull Requests" icon="code-pull-request" href="/optimizing-with-codeflash/codeflash-github-actions">
Automatically find optimizations for Pull Requests with GitHub Actions integration.
```bash
codeflash init-actions
```
</Card>
<Card title="Optimize Workflows with Tracing" icon="route" href="/optimizing-with-codeflash/trace-and-optimize">
End-to-end optimization of entire workflows with execution tracing.
```bash
codeflash optimize myscript.py
```
</Card>
<Card title="Optimize Your Entire Codebase" icon="globe" href="/optimizing-with-codeflash/codeflash-all">
Automatically optimize all functions in your project with comprehensive analysis.
<Card title="Optimize Entire Codebase" icon="globe" href="/optimizing-with-codeflash/codeflash-all">
```bash
codeflash --all
```
</Card>
<Card title="Trace & Optimize Workflows" icon="route" href="/optimizing-with-codeflash/trace-and-optimize">
```bash
codeflash optimize myscript.py
```
</Card>
<Card title="Auto-Optimize Pull Requests" icon="code-pull-request" href="/optimizing-with-codeflash/codeflash-github-actions">
```bash
codeflash init-actions
```
</Card>
</CardGroup>
### Configuration Reference
<CardGroup cols={2}>
<Card title="Python Config" icon="python" href="/configuration/python">
`pyproject.toml` reference
</Card>
<Card title="JS / TS Config" icon="js" href="/configuration/javascript">
`package.json` reference — includes monorepo, scattered tests, manual setup
</Card>
</CardGroup>
### How does Codeflash verify correctness?

View file

@ -1,8 +1,8 @@
---
title: "Optimize Performance Benchmarks with every Pull Request"
description: "Configure and use benchmark integration for performance-critical code optimization"
description: "Configure and use benchmark integration for performance-critical code optimization (Python only)"
icon: "chart-line"
sidebarTitle: Setup Benchmarks to Optimize
sidebarTitle: "Benchmarks (Python)"
keywords:
[
"benchmarks",