#2077·serena

File-system freshness poll costs one os.stat per tracked file on every symbolic call

Author: VolksieCreated Sep 18, 2026Updated Sep 22, 2026

Summary

LanguageServerFileChangeNotifier.poll_and_notify walks the project's source files and stats each one, and it runs on the symbolic tool paths via LspApi.ls_sync_file_system_changes(). The cost therefore scales with the size of the repository and is paid per call, not per change.

On a repository with ~107,000 tracked files that is a large fixed tax on every symbolic query. I would like to discuss bounding it. Opening an issue rather than a PR, because the sensible fix is a design choice rather than an obvious patch.

Where the cost is

poll_and_notify (src/serena/ls_manager.py:303) iterates self._project.gather_source_files() and calls os.stat on each path. Its own docstring is explicit: "The dominant cost is the directory walk plus one os.stat per tracked file; this is intended to be called before symbolic tool invocations rather than on a timer."

It reaches the classic MCP tools as well as the REPL, because LspApiMixin._api() (src/serena/tools/symbol_tools.py:28-32) returns the same LspApi that calls ls_sync_file_system_changes().

To be fair to the current code: gather_source_files does prune ignored directories during the walk (src/serena/project.py:353-355), so this is already much better than walking everything. The remaining issue is simply that the surviving set can still be enormous.

Numbers

Measured on v1.7.0 against an Unreal Engine 5.8 tree. The polling implementation has since been rewritten, so these describe the problem's scale rather than main's behaviour — that is exactly why I am opening an issue instead of sending the local patch:

  • tracked source files: 187,590 before ignore tuning, 107,852 after
  • a full walk: 190s → 59s after the same tuning
  • with a 45s tool timeout, no symbolic call ever reached the language server; clangd received zero didOpen requests across an entire session

The tuning that produced the second column was ours, in .serena/project.yml. The point is that even a well-tuned large repository leaves ~100k files to stat before every call.

Possible directions

Not sure which you would prefer, and I do not want to guess in a PR:

  1. Debounce. Skip the poll if one completed within the last N milliseconds. A handful of symbolic calls in quick succession is the common pattern, and they cannot each need a fresh walk.
  2. Watch instead of poll. watchdog is already a dependency elsewhere in the ecosystem; an OS-level watcher turns the per-call cost into a background one. Bigger change, best outcome.
  3. Budget the walk. Above a configurable file count, poll a subset — for example only directories touched since the last poll — and accept eventual consistency.
  4. Make it configurable. A serena_config.yml setting to disable or throttle the poll for repositories where the trade is not worth it. Least elegant, smallest diff, and unblocks large repositories immediately.

(1) and (4) look like the cheapest useful steps, and I am happy to implement either. (2) is the one I would like to see but it is your call whether that is welcome as an outside contribution.

Environment

Windows 11, Python 3.13, Serena v1.7.0 where measured; main at bd2712fd reviewed for the code references above. Repository: Unreal Engine 5.8 source plus three game projects, C++/C#/Python, four language servers configured.