Good catch on the fill-ing because I used 5 assuming each would add an allocation, but there’s actually 2+ allocations for Arrays wrapping Memory buffers in v1.11+, which suggests to me that ones(MaybeBig{Int}, ...) isn’t allocating the one instance. It seems to be corroborated by benchmarking BigInt arrays:
julia> @btime BigInt($1)
57.099 ns (2 allocations: 40 bytes)
1
julia> @btime Vector{BigInt}(undef, $2)
23.015 ns (2 allocations: 80 bytes)
2-element Vector{BigInt}:
#undef
#undef
julia> @btime Vector{BigInt}(undef, $100); # still 2 allocations for 100 undef
65.164 ns (2 allocations: 928 bytes)
julia> @btime ones(BigInt, $2) # 1 BigInt filling 1 2-Array adds up
82.070 ns (4 allocations: 120 bytes)
2-element Vector{BigInt}:
1
1