-
-
Notifications
You must be signed in to change notification settings - Fork 701
Potential performance issue: linear template parameter lookup in reliesOnTemplateParameters #22846
Copy link
Copy link
Open
Description
Hi,
While exploring template instantiation logic in DMD, I noticed a potential performance bottleneck in templatesem.d, specifically in the reliesOnTemplateParameters function.
Issue
In multiple visitor cases (e.g., TypeIdentifier), the code performs a linear scan over all template parameters:
foreach (tp; tparams)
{
if (tp.ident.equals(t.ident))
return true;
}
This check appears to be executed frequently during template deduction and semantic analysis, and is also used recursively when traversing complex types.
Why it might matter
- This introduces O(n) lookup per check, where n = number of template parameters
- For templates with many parameters or deeply nested types, this can multiply quickly
- The function is called repeatedly during template matching and deduction
Possible direction
One possible improvement could be:
- Precomputing a hash-based lookup (e.g., identifier → parameter set)
- Or using a more efficient structure to avoid repeated linear scans
Question
Is this something that has already been considered or optimized elsewhere?
I’d be happy to explore this further and try benchmarking potential improvements if this direction makes sense.
Thanks!
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels