Skip to content

v0.20.0

Choose a tag to compare

@github-actions github-actions released this 27 Oct 21:40
· 13 commits to main since this release
Immutable release. Only release title and notes can be modified.
51de97e

Large trees build, load and update much faster on less memory. On a
302,000-file corpus (Linux, LLVM, Rust, Kubernetes, same machine against
v0.19.0) a build takes about 185 s instead of 464 s, a load 2.4 s instead
of 24 s, resident memory after a build is 1,152 MB instead of 1,590 MB,
symbol search is about 10 times faster, and a restart reads only the
folders that changed. A one-file update takes about 3 ms at any size.
Search results are unchanged.

Slowdowns, named: a path-filtered search on an index that was just built
measured 19% slower on the large corpus (fine once loaded from disk); the
sharded build left searches 0 to 13% slower in same-machine runs; mimalloc
adds 17 MB of resident memory on a small tree. Each entry below says what
it buys.

Known limits (#234): on a 4-core machine with searches that take 1 to 3 s,
a change waiting for the index lock can still keep new searches waiting
about 2 s, and peak resident memory now counts the mapped index file's
page-cache pages, which the OS can evict.

Upgrading: the index format is now v13 (magic FCSIDX10): the first
start after the upgrade rebuilds the index once, with no config change.
A loaded index maps its file, so resident memory includes page-cache pages
of the index that the OS can evict and share; /api/diagnostics reports
them as mapped_postings_bytes. Windows still decodes posting lists onto
the heap.

Changed

  • Loading and saving an index are about 20% faster. The index file's
    checksum uses the CPU's carry-less multiply (crc32fast) instead of a
    table: it was 16% of a load's instructions. Registering the files' paths
    for import resolution no longer hashes each path several times, and runs
    alongside restoring the symbols. On the 302,000-file corpus a load takes
    2.39 s instead of 2.79 s (median of 6 interleaved runs, same machine); on
    tokio + Django a load takes 83 ms instead of 107 ms and a save 120 ms
    instead of 154 ms. The file format is unchanged.
  • Symbols take half the memory. Each distinct symbol name is now
    stored once, and a symbol takes 16 bytes instead of 48 plus its own copy
    of its name. On the 302,000-file real corpus symbols take 212 MB instead
    of 405 MB and resident memory after a build is 1,152 MB instead of
    1,490 MB (same machine, median of 3 against c718f73); a loaded Linux
    kernel index holds 162 MB of heap instead of 286 MB. Saves are 9 to 12%
    faster, a one-file update about 20% faster, searches unchanged. The
    index format is now v13 (magic FCSIDX10): the first start after the
    upgrade rebuilds the index once.
  • Bulk changes reach the index about twice as fast. When many files
    change at once (a branch switch, a formatter run), the watcher now adds
    the new trigrams of the changed files in one parallel pass, as a build
    does, instead of one file at a time under the write lock. Installing 512
    changed files takes 24 to 37 ms instead of 75 to 241 ms. In
    watch_load on 100,000 files, with 2,000 files rewritten a second while
    four people search, the index caught up 41 to 43 s after the stream
    stopped instead of 99 to 106 s, and search p50 fell from 2.0 s to 1.6 s
    (same machine). A one-file edit takes the same time as before.
  • Searches are up to twice as fast: the binaries use mimalloc. The
    server, fcs and the benchmarks use mimalloc (v2) instead of the system
    allocator. With glibc's allocator a server that had just built its index
    answered about 2x slower than after a restart (the allocator's state
    after the build, not the index). Same machine against a708ca2: on the
    302,000-file corpus a common word takes 87 ms instead of 181 ms, an
    identifier 44 ms instead of 78 ms, a regex with a literal 75 ms instead of
    110 ms, symbol searches about 25% less, a build 7% less and a save 43%
    less, and resident memory after a build is 3% lower. On tokio + Django
    queries take 7 to 38% less and a build 10% less. The cost: resident
    memory after a build there is 17 MB higher (100 to 117 MB).
  • A loaded index keeps its posting lists in the index file. The
    server maps the file and a query decodes only the lists for its own
    trigrams, so the lists sit in the page cache, which the OS can evict and
    share, instead of on the heap: at 302,000 files a loaded index holds
    6 MB of posting data on the heap instead of about 479 MB (350 MB of the
    file is mapped instead), and loads 17% faster (4.1 s to 3.4 s, same
    machine, median of 3). Query times are unchanged. Removing or changing a file
    costs one bit for the mapped lists instead of a pass over every list.
    Saves while the server runs (checkpoints) now keep every file's id,
    writing a removed file as an empty slot, copy unchanged lists from the
    mapped file as they are, and leave the server reading the file they
    wrote; the save at shutdown compacts the slots away. index.memory in
    /api/diagnostics reports the mapped bytes as mapped_postings_bytes.
    Index format v11, now v12 (see Fixed; the first start after upgrading
    rebuilds the index once). Known limitation: on Windows, which cannot replace a mapped file,
    the lists are still decoded onto the heap at load.
  • Loading a saved index is about 2.5 times faster. With one file
    changed since the save, a load of the 302,000-file real corpus took
    10.3 s and now takes 4.1 s (same machine, median of 5). A load used to
    renumber the files that survived, which rebuilt every posting list when
    even one file had changed; each saved file now keeps its id and the
    changed and deleted ones are tombstoned, as a removal at runtime is.
    From the same profile: the checksum is computed eight bytes at a time,
    path tables use a faster hash, directory counts are added once per
    directory, symbols are moved rather than copied, and the ranking
    metadata pass runs on every core.
  • Restarts read only the folders that changed. After loading a saved
    index, the server looked for new files by walking every folder under the
    roots: at 302,000 files, 2.6 s with the file system cache warm and 9.2 s
    cold, while answers said the index was incomplete. The last complete walk
    now saves each folder's modification time and a fingerprint of its
    ignore files, and a restart reads only the folders whose time or ignore
    files changed: 0.18 s warm, 1.3 s cold. A full walk still happens after
    a configuration change, a change to the global excludes file, or when
    the index has no stamps yet. Index format v10 (now v12): the
    first start after upgrading rebuilds the index once. Known limitation: on a file system
    that does not update a folder's time when its entries change, a file
    added while the server was stopped is found only once it or its folder
    changes again.
  • About 10% less memory on large trees: each file's path is held once.
    The ranking metadata, the import resolver's path tables and the import
    lists kept their own copies of every path (five to eight per file); they
    now share the file store's one copy. On 4 cores the 302,000-file real
    corpus (Linux, LLVM, Rust, Kubernetes) sits at 1,504 MB resident after a
    build instead of 1,665 MB, and a loaded Linux kernel index holds 35 MB
    less heap (468 to 433 MB, counted by allocation). Results are identical. One slowdown, named:
    a search with a path filter (file:, include/exclude globs) on an index
    that was just built measured 19% slower on the large corpus (95 to
    113 ms), because the paths it reads are spread through the heap; on an
    index loaded from disk it is as fast as before. Other searches measured
    2 to 12% faster.
  • Searches with many candidate files sort only what they read. Every
    search reads its candidates best first and usually stops at its match
    budget a thousand or two files in, but it sorted all of them first: at
    302,000 candidates, scoring and sorting took 31 to 34 ms. The order is
    now settled lazily (a selection of the next part, then a sort of just
    that part), with the same order. Same-machine runs at 302,000 files:
    short-text search -15%, regex with a literal -10%; other queries within
    noise.
  • Symbol search about 12 times faster on large trees. It tested every
    symbol of every file whose text contained the query: for Error on the
    302,000-file real corpus (Linux, LLVM, Rust, Kubernetes) that was 5.3
    million symbols in 85,000 files, to find the 7,000 files defining a
    matching name. A dictionary of the distinct case-folded symbol names
    (1.6 million, one string searched with memmem) now lists the files and
    symbol kinds behind each name, and a case-insensitive search ranks files
    from it directly; a case-sensitive one tests only those files. Results
    are the same. The lines a match is shown on are found without splitting
    the whole file into lines. Same-machine runs: Error 522 to 42 ms and
    Req 589 to 42 ms at 302,000 files, 22 to 9 ms and 15 to 6 ms on tokio +
    Django.
    What it costs: the dictionary takes memory (63 MB at 302,000 files,
    46 MB for the Linux kernel; resident +4%), and it is built after every
    build on one thread (about 2 s at 302,000 files; on all cores it took
    half the time but fragmented memory: resident grew 160 MB). It is saved
    with the index, so a load restores it instead (index format v9: the
    first start after upgrading rebuilds the index once). Files changed after the
    dictionary was built are searched symbol by symbol until a sixteenth of
    the files (at least 4,096) have changed; the update that crosses that
    line rebuilds it under the write lock.
  • Builds and large watcher batches up to twice as fast.
    Merging a batch into the index ran on one thread and was half of a
    build's time; posting-list inserts were four fifths of that. The posting
    lists are now split into 64 shards by trigram and each batch is merged
    shard by shard in parallel. On 4 cores the 302,000-file real corpus
    (Linux, LLVM, Rust, Kubernetes) builds in 211 s instead of 471 s, tokio +
    Django in 5.6 s instead of 8.1 s, with the same index and the same
    memory. Searches measured 0 to 13% slower in same-machine runs, on a
    just-built and on a reloaded index alike (tokio + Django; up to 19% for
    one query on the large corpus, from 3 rounds). In one 5-round run the
    common-word search was slower in every round (+11%); in a second, no
    query was, and a regex that never touches the changed code moved as much
    as any. So most of it is noise or code layout, but a small real cost is
    not ruled out.
    corpus_bench --loaded-queries now also times the queries on the
    reloaded index.
  • Less memory after a build or a load (Linux). A build frees far more
    than the index it keeps (file contents, per-batch trigram sets, merge
    buffers), and the allocator held on to those pages, so resident memory
    stayed high until a restart. The server now hands them back to the
    system once a build or a load is done: tokio + Django went from 135 MB
    to 107 MB resident, the Linux kernel tree from 793 MB to 709 MB, in 8 and
    36 ms, outside the write lock. glibc only; macOS, Windows and the musl
    build are unchanged.

Added

  • Where the memory goes. /api/diagnostics now reports the index's
    estimated heap per structure (index.memory: posting lists, the file
    table, symbols, references, the dependency graph, imports), largest
    first, next to the process's resident memory (index.resident_bytes,
    Linux). corpus_bench prints the same breakdown as a table, with a
    "not estimated" row for the allocator's share, and reports each part as
    a benchmark metric. The scale scoreboard records it per scenario. A
    change that grows memory now shows which structure grew. Measured this
    way, a just-built index holds more than the same index after a restart
    (tokio + Django: 78 MB against 44 MB of heap), because posting lists
    built by inserts keep spare capacity.
  • An instruction-count gate on every push to main. The Benchmarks
    workflow now counts, under callgrind, the instructions each operation
    takes on tokio + Django (build, every query, an incremental update,
    save, load) and fails when one takes more than 3% more than at the last
    passing push (scripts/bench/icount.sh, corpus_bench --icount).
    Counts barely move between runners, unlike wall time, so added work
    shows the day it lands. Counts are published only from a passing run,
    so the run stays red until the work is removed, or accepted with an
    Accept-instructions: line in the commit message. The Criterion suites
    no longer run in CI (they still run with cargo bench), and the job
    takes about as long as before (18 minutes on its first run, 20 before).

Fixed

  • The background integrity check held the index lock for seconds.
    Since posting lists are read from the mapped index file, checking a
    file's trigrams decoded each whole posting list to test one file in it,
    so one step of the scrub ([diagnostics] scrub, on by default) held the
    read lock for 2.3 to 3.1 s on the 302,000-file corpus. A build's last
    step, the watcher and the searches queued behind it waited that long; the
    nightly scale scoreboard caught it as lock-stall captures after a build
    and a restart. The check now looks up the one container that would hold
    the file, without decoding the list: a step holds the lock 0.13 to 0.6 s
    (same machine, 256 files). /api/check and fcs check use the same
    check and gain the same.
  • The end of a build kept searches out for about 2 s on large trees.
    The symbol name dictionary (which made symbol search about 12 times
    faster) was rebuilt under the write lock at the end of every build and
    after every large batch of symbol changes: about 2 to 2.8 s at 200,000
    files on 4 cores, longer than the 2 s a lock-stall capture allows. The
    server now builds it under the read lock, so searches go on, and takes
    the write lock only to swap it in, marking the symbols that changed
    meanwhile for a direct check as any later change is. Library callers
    (SearchEngine::finalize) still rebuild it in place.
  • A restart missed a file that had been too large or binary. The
    restart walk (above) skipped folders whose time had not changed, but a
    file skipped for its size or contents is not in the load's checks, and
    cutting it down rewrites the file, not its folder, so it never joined the
    index. Each folder stamp now counts the folder's eligible files, and a
    folder holding a different number in the index is read again (such
    folders are read on every restart). Index format v12. Found by the
    lifecycle model test on main.
  • A regex could take in a CRLF line's \r. one[^A-Za-z0-9_] matched
    line one on a line ending in \r\n, where rg --crlf does not: the
    \r now belongs to the line ending for every pattern, not only $.
    Found by a generated query in the ripgrep backtest.
  • Saves take a third of the instructions they did. B6's faster CRC
    cost more per call, and the save called it for every few bytes bincode
    wrote, which made saves 7% dearer; the write buffer now sits in front of
    the CRC, which runs over whole 64 KiB buffers. tokio + Django: 1,269 to
    432 million instructions per save (callgrind, one thread).
  • The symbol-search benchmark timed a search no front end runs. The
    library's search_symbols (used by the corpus benchmark, the validator
    and tests) ran an older single-pass search; the web API, gRPC, MCP and
    fcs run the two-phase one. search_symbols now runs that one too, so
    the published symbol numbers are what a user waits for: on the
    302,000-file corpus about 510 ms for an exact name and 580 ms for a
    prefix, not the 350 ms the benchmark showed (tokio + Django: 19 and
    13 ms, not 13 and 8). Nothing a user runs got slower; the benchmark now
    measures it. Making these faster is the next item (a symbol name index).
  • fcs check --live --all-content was cut off on a large index. The
    server's whole-request timeout (request_timeout_secs, 30 s) applied to
    /api/check, so a check that read every file of a large tree answered
    504 while the client was ready to wait an hour. The check runs one at a
    time and only reads, so it is no longer timed out. Found by the scale
    scoreboard on a 200,000-file tree with real-sized files.
  • Folders that could not be read went missing without a word. When
    the build, a restart's check or a rescan could not list a folder
    (permission denied, an I/O error), it logged a debug line and skipped
    it, so its files were missing from every search. Each such folder is
    now logged as a warning and counted with every search: "1 folder could
    not be read, so the files in it are missing from the index", in the web
    UI ("1 folder unreadable"), fcs, MCP, /api/status and fcs check --live. The count clears when a later scan (a restart, a rescan) can read the
    folder.
  • Folders the watcher could not watch were not reported. A folder the
    file watcher could not list was dropped silently, and one it could not
    watch (the OS watch limit) was only logged. Both are now counted while
    watching ("2 folders not watched"): changes in them reach the index only
    at the next rescan or restart.
  • A file-watcher error now triggers a rescan. An error from the OS
    watcher (its event stream failed) was logged and nothing else, so the
    events it lost were lost for good. The watched folders are now
    reconciled with the disk, at most once every five minutes so a repeating
    error cannot keep a rescan of a large tree running.

Documentation

  • Benchmark numbers in the README, the book and the site are rendered,
    not typed.
    They come from one pinned Benchmarks run
    (docs/bench/published.json), now the run for c635718, which includes
    the faster build: tokio + Django builds in 4.9 s instead of 5.5 s. CI
    fails when a page and the pinned run disagree. The file-format page said
    format v7; the index has been v8 since v0.16.0.
  • Benchmark numbers now match what fcs does. The README, the book's
    benchmark pages and the project site showed numbers from 8 September
    (before v0.17.0), with a common word at about 1 ms. They now show the
    v0.19.0 run: a common word over tokio + Django is 24.6 ms at p50, an
    identifier 7.8 ms, and a query with no match 0.6 µs (since refreshed
    from a later run, see above).
  • The v0.17.0 slowdown, named. v0.17.0 raised the match budget from
    512 to 32,768, so a search ranks many more matches before it returns
    page one. On a ~6,300-file repository that made common-word text
    searches about 10 times slower (about 5 ms to about 55 ms on the same
    machine) and regexes with no literal about 30 times slower (about 3 ms to
    about 100 ms). It buys ranking quality: page one now holds 81% of the
    exhaustive top 50 instead of 10%. Queries with few matches and index
    builds did not change. See the book's Search limits page.
  • The release run-book in docs/DEVELOPMENT.md now matches how releases
    are cut, and the instruction files say which docs repeat which numbers so
    they are updated together.

Install

Download the archive for your platform below, unpack it, and put fast_code_search_server and fcs on your PATH.
Each archive also contains config.toml.example, the startup unit files (deploy/) and the CLI and startup guides.

Platform Archive
Linux x86_64 (glibc) fast_code_search-v0.20.0-x86_64-unknown-linux-gnu.tar.gz
Linux x86_64 (static, musl) fast_code_search-v0.20.0-x86_64-unknown-linux-musl.tar.gz
macOS Apple silicon fast_code_search-v0.20.0-aarch64-apple-darwin.tar.gz
macOS Intel fast_code_search-v0.20.0-x86_64-apple-darwin.tar.gz
Windows x86_64 fast_code_search-v0.20.0-x86_64-pc-windows-msvc.zip

Verify a download with the .sha256 file next to it: sha256sum -c fast_code_search-v0.20.0-<target>.tar.gz.sha256.
Each archive is also signed through Sigstore; with cosign installed:

cosign verify-blob --bundle fast_code_search-v0.20.0-<target>.tar.gz.sigstore.json \
  --certificate-identity-regexp '^https://github.com/jburrow/fast_code_search/' \
  --certificate-oidc-issuer https://token.actions.githubusercontent.com \
  fast_code_search-v0.20.0-<target>.tar.gz

Other ways to install: cargo binstall fast_code_search (downloads these archives), cargo install fast_code_search (builds from crates.io), or the container image ghcr.io/jburrow/fast_code_search:0.20.0.

First run: fast_code_search_server --init config.toml, add your paths, start the server, then fcs 'fn main'.
Full changelog: https://github.com/jburrow/fast_code_search/blob/main/CHANGELOG.md