[all-commits] [llvm/llvm-project] b6f389: [clang-doc] Improve complexity of Index constructi...

Paul Kirth via All-commits all-commits at lists.llvm.org
Tue Mar 3 09:10:08 PST 2026


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: b6f389e005d7cf4bc0df0c594cd65d625a96ad01
      https://github.com/llvm/llvm-project/commit/b6f389e005d7cf4bc0df0c594cd65d625a96ad01
  Author: Paul Kirth <paulkirth at google.com>
  Date:   2026-03-03 (Tue, 03 Mar 2026)

  Changed paths:
    M clang-tools-extra/clang-doc/Generators.cpp
    M clang-tools-extra/clang-doc/JSONGenerator.cpp
    M clang-tools-extra/clang-doc/MDGenerator.cpp
    M clang-tools-extra/clang-doc/Representation.cpp
    M clang-tools-extra/clang-doc/Representation.h
    M clang-tools-extra/clang-doc/YAMLGenerator.cpp
    M clang-tools-extra/unittests/clang-doc/ClangDocTest.cpp
    M clang-tools-extra/unittests/clang-doc/GeneratorTest.cpp

  Log Message:
  -----------
  [clang-doc] Improve complexity of Index construction (#182621)

The existing implementation ends up with an O(N^2) algorithm due to
repeated linear scans during index construction. Switching to a
StringMap allows us to reduce this to O(N), since we no longer need to
search the vector.

The `BM_Index_Insertion` benchmark measures the time taken to insert N
unique records into the index.

| Scale (N Items) | Baseline (ns) | Patched (ns) | Speedup | Change |
|----------------:|--------------:|-------------:|--------:|-------:|
| 10              | 9,977         | 11,004       | 0.91x   | +10.3% |
| 64              | 69,249        | 69,166       | 1.00x   | -0.1%  |
| 512             | 1,932,714     | 525,877      | 3.68x   | -72.8% |
| 4,096           | 92,411,535    | 4,589,030    | 20.1x   | -95.0% |
| 10,000          | 577,384,945   | 12,998,039   | 44.4x   | -97.7% |

The patch delivers significant improvements to scalability. At 10,000
items, index construction is **~44 times faster**, confirming the
complexity reduction from O(N^2) to O(N). The crossover point where the
new map-based approach beats the vector-based approach appears to be
around N=64.

Since the index is typically larger than 64 for files of non trivial
complexity, and users will typically be building documentation for an
entire project with many files, all normal usage should benefit from
this change.

Other benchmarks show minor regressions, though in a typical build of
LLVM documentation index construction takes up a larger amount of
runtime than any of these other components.



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list