[LifetimeSafety] Cache lifetimebound macro lookup (#205250)
Cache lifetimebound macro spelling lookup used by fix-it suggestions.
Current cache strategy:
- During cache build, collect macro names that have ever been defined as
a lifetimebound attribute spelling.
- During lookup, only visit those cached macro names, find the active
definition at the fix-it location, and re-check that the active
definition still has lifetimebound spelling.
- If multiple matching macros are active at the fix-it location, use the
most recently defined one.
Performance:
| Case | Before 359bfe6 | 359bfe6| After Cached |
|-------------------------------------------------------------|----------------:|---------------:|-------------:|
| C++ no diagnostics (8k macros, 5k safe functions) | 42.5 ms | 44.2 ms
| 47.0 ms |
| C++ 10 diagnostics, 8k macros | 23.2 ms | 23.4 ms | 17.5 ms |
| C++ 200 diagnostics, macro passed via command line option | 24.8 ms |
24.6 ms | 29.3 ms |
| C++ 200 diagnostics, 8k macros | 26.3 ms | 41.7 ms | 27.9 ms |
| C++ stress: 1000 diagnostics, 20k macros, no matching macro
(simulating worst case scenario) | 40.8 ms | 386.7 ms | 78.9 ms |
AI Usage: Performance experiment assisted by Codex.
Follow up of https://github.com/llvm/llvm-project/pull/204045