performance.md

 1How to use our internal tools to profile and keep Zed fast.
 2
 3# Flamechart/CPU profiling
 4
 5See what the CPU spends the most time on. Strongly recommend you use
 6[samply](https://github.com/mstange/samply). It opens an interactive profile in
 7the browser (specifically a local instance of [firefox_profiler](https://profiler.firefox.com/)).
 8
 9See [samply](https://github.com/mstange/samply)'s README on how to install and run.
10
11The profile.json does not contain any symbols. Firefox profiler can add the local symbols to the profile for for. To do that hit the upload local profile button in the top right corner.
12
13<img width="851" height="613" alt="image" src="https://github.com/user-attachments/assets/cbef2b51-0442-4ee9-bc5c-95f6ccf9be2c" />
14
15# Task/Async profiling
16
17Get a profile of the zed foreground executor and background executors. Check if
18anything is blocking the foreground too long or taking too much (clock) time in
19the background.
20
21The profiler always runs in the background. You can save a trace from its UI or
22look at the results live.
23
24## Setup/Building the importer:
25
26- Clone the repo at git@github.com:zed-industries/tracy.git on v0.12.2 branch
27- `cd profiler && mkdir build && cd build`
28- Run cmake to generate build files: `cmake -G Ninja -DCMAKE_BUILD_TYPE=Release ..`
29- Build the importer: `ninja`
30- Run the impoter on the trace file: `./tracy-import-miniprofiler /path/to/trace.miniprof /path/to/output.tracy`
31- Open the trace in tracy:
32  - If you're on windows download the v0.12.2 version from the releases on the upstream repo
33  - If you're on other platforms open it on the website: https://tracy.nereid.pl/ (the version might mismatch so your luck might vary, we need to host our own ideally..)
34
35## To Save a Trace:
36
37- Run the action: `zed open performance profiler`
38- Hit the save button. This opens a save dialog or if that fails to open the trace gets saved in your working directory.
39- Convert the profile so it can be imported in tracy using the importer: `./tracy-import-miniprofiler <path to performance_profile.miniprof> output.tracy`
40- Go to <https://tracy.nereid.pl/> hit the 'power button' in the top left and then open saved trace.
41- Now zoom in to see the tasks and how long they took
42
43# Warn if function is slow
44
45```rust
46let _timer = zlog::time!("my_function_name").warn_if_gt(std::time::Duration::from_millis(100));
47```