Performance hit in generated function using dispatching on argument

I’m trying to use generated functions since I need to loop over a sum of elements from different vectors, but the vectors that are used in the sum depend on the type of one of the arguments. The last argument is an instance of a parametric type, but it’s not actually used in the final code of the function, just in finding what terms have to be summed over.

I generate the function

‘’’
@generated function sumFunc(datastruct, parametrictype)
return getBody(parametrictype)
end
‘’’

So again, there is no mention of parametrictype in my function body. If I benchmark this function, the time of execution will be about 80ns for one specific case. However, if I just type in the body directly to a function, it will evaluate in 40ns. Adding another argument that does nothing:

@generated function sumFunc(datastruct, parametrictype, unused_parametrictype)
 ...
end

only adds about 2ns to the evaluation time, which seems more reasonable.

I understand this may be a bit vague, but the actual code is not super easy to post, so if anyone has any ideas without me having to post the actual code, that would be great.