This change optimizes the basename matching logic in `SampleProfileMatcher::matchFunctionsWithoutProfileByBasename` by replacing the existing O(N*M) nested loop with an O(N+M) hash-based lookup, while strictly preserving the original matching semantics. The previous implementation relied on a substring heuristic (`ProfName.contains(BaseName)`) to bypass expensive demangling operations during the nested iteration; however, in codebases with common or overlapping function names, this heuristic frequently evaluated to true, resulting in redundant demangling and quadratic time complexity. The updated approach demangles each profile name exactly once and utilizes a `StringMap` to perform O(1) lookups against the orphan functions. This eliminates the need for the substring pre-check while maintaining the exact same constraints: establishing a strict 1:1 mapping between orphaned IR functions and profile entries, and correctly identifying and rejecting ambiguous matches where multiple entities share the same demangled basename. Results in a 9x speedup on a large module with common basenames.
42 KiB
42 KiB