Ray's Knowledge Base
Unlock

A name that Doxygen lists as both a class and a function makes the Sphinx environment grow with each rebuild

PitfallVerified 5 Nov 2026Holds project: dftracer-utils
Pitfall. The symptom, what causes it, and the fix that was run and seen to work.

Symptom#

sphinx-build into the same output folder gets slower and bigger on each rebuild. One build was 60.6 GB of RAM, and the laptop panicked. The saved docs/build/html/.doctrees/environment.pickle was 5.47 GB. A healthy file is about 18 MB. A fresh build into an empty folder looks fine.

Cause#

The API index generator wrote dstd::Unexpected as a class entry and as a function entry. Doxygen reports the deduction guide of the class as a function with the same name. The duplicate C++ declaration is merged again at each incremental rebuild. The count per rebuild was 4, 13, 40, 121, about three times more each time.

Fix#

Make the generator skip a function that has the name of a class. In docs/scripts/generate_api_index.py, drop such function entries. Delete the bad environment.pickle once, because loading it needs more than 24 GB. Run one docs build at a time, with a memory cap. After the fix, 4 rebuilds gave a count of 1, 2, 2, 2, a 1.0 GB peak and 0 warnings.

Evidence#

  • A single fresh build did not show the bug. Only repeated rebuilds into one doctree folder did.
  • grep -E "Duplicate C\+\+" <log> finds the warning.
  • Two parallel sphinx-build runs made the 60.6 GB and 31.8 GB processes in the panic report.

Also found by searching

  • sphinx-build uses 60 GB of memory
  • sphinx environment.pickle is several GB
  • sphinx incremental rebuild gets slower and bigger each time
  • doxygenfunction and doxygenclass for the same name
  • how do I stop a docs build from running out of RAM