By the way, the telltale thing to look for to identify cases like this is a red Core.Box annotation in your @code_warntype:
julia> @code_warntype f2(X)
Variables
#self#::var"#myfun#2"{Int64}
X::Vector{UInt64}
...
...
...
│ %11 = Core.getfield(#self#, :T)::Core.Box
...
...