codebook: [BUG]: FreeBSD performance issues

From https://github.com/blopker/codebook/issues/78

Codebook will now run at full throttle, maximising the CPUs and making it unusable as a whole. I've had to rollback from v0.3.0. Do you want me to open a new issue or should I provide more info here?
Running Helix and FreeBSD on amd64, with a Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz. 8 GB RAM.

# cat thesis.typ | wc
    1153    6406   44776

(that's lines, words, bytes being reported respectively for a file with a mix of prose and Typst syntax)

I was a bit concerned already with codebook@v0.2.13 sucking up around 30-40 % of the CPU time for about 5 seconds when I saved this file, but it was doable.

With the latest version codebook would max out all four CPUs while I was editing a single line (not when the file was saved), which sounds weird? Maybe that can give you a hint.

I'm sorry that I can't read Rust but I can at least try out new version.
Stress testing with a bigger file:

# cat ../python/venv/lib/python3.11/site-packages/matplotlib/patches.py | wc
    4720   16929  163516

Arbitrary results after having opened the editor and started typing out a long line of text (+80 chars) of english words and then stop and wait.

v0.2.13: +300 % CPU time (~8 seconds until cooling down to ~0 %)
v0.3.0: +350 % (~10 seconds)

Re-testing the prose file from before:
v0.2.13: +80 % (~3 seconds)
v0.3.0: +300 % (~10 seconds)

I can't say much about these fluff numbers, new version ran noticeable heavier on the prose (compared to before) and about the same-ish on the large python file. Your best bet is profiling.

Edit: I don't use other LSP servers for Typst or Python.

About this issue

  • Original URL
  • State: open
  • Created a year ago
  • Comments: 15 (8 by maintainers)

Most upvoted comments

Hey! I’m glad it’s working better for you now, and thanks for the offer to continue testing.

I didn’t intend to support freebsd at the beginning, but it’s been interesting to learn more about. I’ll leave this open in case anyone has more clues.

Small update here, I’ve added a benchmark CI job and getting similar numbers on Linux as my local Mac: https://github.com/blopker/codebook/actions/runs/15548865047/job/43775474246 (18ms to check the full Beowulf text on average). Something is going on specifically with FreeBSD.

Hey! I finally got a local vm with freeBSD on it, but still need to set up a dev environment.

For benchmarking, the ‘codebook’ crate (as opposed to ‘codebook-lsp’) has a not-published bin that I use for testing on individual files. It has a --benchmark argument that I use to profile performance. It’s fairly rudimentary right now, and not stable, but a good place to experiment.

I’d love to make benchmarking more formalized to track performance between releases.

The LSP crate is really just the translation and parallelization layer. The core performance issues happen in the Codebook crate.

I will say that prose is the worst case for performance. Tree sitter is able to reduce a code file to a minimal set of words for processing, where the whole prose file needs to be checked.

Going to investigate poor interactions with FreeBSD and musl: https://raniz.blog/2025-02-06_rust-musl-malloc/