On Tuesday, 29 November 2022 at 07:15:25 UTC, Walter Bright wrote:
>On 11/27/2022 1:29 AM, FeepingCreature wrote:
>- But also if we're talking about number of instantiations,
hasUDA
andgetUDA
lead the pack. I think the way these work is just bad - I've rewritten all my ownhasUDA
/getUDA
code to be of the formudaIndex!(U, __traits(getAttributes, T))
- instantiating a unique copy for every combination of field and UDA is borderline quadratic - but that didn't help much even though-vtemplates
hinted that it should.-vtemplates
needs compiler time attributed to template recursively.
hasUDA and getUDAs are defined:
enum hasUDA(alias symbol, alias attribute) = getUDAs!(symbol, attribute).length != 0;
template getUDAs(alias symbol, alias attribute)
{
import std.meta : Filter;
alias getUDAs = Filter!(isDesiredUDA!attribute, __traits(getAttributes, symbol));
}
These do look pretty inefficient. Who wants to fix Phobos with FeepingCreature's solution?
Well, in his codebase I ended up just redefining hasUDA
in terms of udaIndex
, and even though hasUDA
led the pack in -vtemplates
this didn't actually result in any noticeable change in speed. I think even though hasUDA
gets instantiated a lot, it doesn't result in much actual compile time. Unfortunately there's no good way to know this without porting everything, which is I think the actual problem.