I realised with the allocation profiler that our model allocates a lot when concatenating strings like "a" * "b". Is there a way to avoid allocation in such cases? I tried with InternedStrings and intern("a" * "b"), but that didn’t change anything…
In Julia 1.8+ there’s a LazyString type which you might want to try to represent "a" * "b" instead. Note that LazyString construction still allocates the wrapper and a tuple though, so this is probably only worthwhile for concatenating larger strings.
Don’t know anything about interned strings, but I think this would evaluate "a" * "b" first, and then call intern() on the result, so not surprised that it didn’t change. Can you intern("a") * intern("b") or something?
julia> function Base.:*(a::StaticString{N}, b::StaticString{M}) where {N,M}
t_a = Tuple(a)
t_b = Tuple(b)
StaticString(ntuple(N+M) do i
if i <= N
t_a[i]
else
t_b[i-N]
end
end)
end
julia> static"abc" * static"defgh"
static"abcdefgh"8
julia> @allocated static"abc" * static"defgh"
0