Skip to content

Commit 54b56d9

Browse files
lkdvosclaude
andcommitted
Drop the recycling of the tree vectors in fsbraid, which gives no measurable speedup
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 6f912e4 commit 54b56d9

2 files changed

Lines changed: 8 additions & 16 deletions

File tree

‎src/fusiontrees/braiding_manipulations.jl‎

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,8 @@ function artin_braid(src::FusionTreeBlock{I, N, 0}, i; inv::Bool = false) where
9292
n = length(src) # braiding a complete block keeps its size
9393
return artin_braid!(Matrix{sectorscalartype(I)}(undef, n, n), src, i; inv) # zeroed by `artin_braid!`
9494
end
95-
# `U` is overwritten with the braid matrix of `src`, a complete block; the trees of the result are
96-
# stored in `trees` if given
97-
function artin_braid!(
98-
U::AbstractMatrix, src::FusionTreeBlock{I, N, 0}, i; inv::Bool = false, trees = nothing
99-
) where {I, N}
95+
# `U` is overwritten with the braid matrix of `src`, a complete block
96+
function artin_braid!(U::AbstractMatrix, src::FusionTreeBlock{I, N, 0}, i; inv::Bool = false) where {I, N}
10097
1 <= i < N || throw(ArgumentError("Cannot swap outputs i=$i and i+1 out of only $N outputs"))
10198
size(U) == (length(src), length(src)) || throw(DimensionMismatch(lazy"braid matrix of size $(size(U)) for a block of $(length(src)) trees"))
10299
isempty(src) && return src => U
@@ -110,7 +107,7 @@ function artin_braid!(
110107
isdual = src.isdual[1]
111108
isdual′ = TupleTools.setindex(isdual, isdual[i], i + 1)
112109
isdual′ = TupleTools.setindex(isdual′, isdual[i + 1], i)
113-
rows = TreeRows(fusiontreetype(I, N, 0), length(src), trees)
110+
rows = TreeRows(fusiontreetype(I, N, 0), length(src))
114111

115112
oneT = one(sectorscalartype(I))
116113
fill!(U, zero(oneT))
@@ -344,18 +341,14 @@ end
344341

345342
dst, U = repartition(src, Val(numind(src)))
346343

347-
# the swaps keep the size of the block, so that the tree vector and the matrices of the
348-
# previous step are recycled (except for the trees of `src`, which are part of the key)
349-
trees = nothing
344+
# the swaps keep the size of the block, so that the matrices of the previous step are recycled
350345
U_tmp = Matrix{sectorscalartype(I)}(undef, length(dst), length(dst))
351346
U_spare = nothing
352347
braid_style = BraidingStyle(I)
353348
for s in permutation2swaps(p′)
354349
_check_levels(braid_style, levels, s)
355350
inv = levels[s] > levels[s + 1]
356-
dst′, _ = artin_braid!(U_tmp, dst, s; inv, trees)
357-
trees = dst.trees === src.trees ? nothing : dst.trees
358-
dst = dst′
351+
dst, _ = artin_braid!(U_tmp, dst, s; inv)
359352
U_spare, U = U, U_spare isa typeof(U_tmp) ? mul!(U_spare, U_tmp, U) : U_tmp * U
360353
l = levels[s]
361354
levels = TupleTools.setindex(levels, levels[s + 1], s)

‎src/fusiontrees/fusiontrees.jl‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -294,17 +294,16 @@ end
294294

295295
# The trees of the destination block of a block manipulation, in the order in which they are
296296
# produced, and the row of each of them in the transformation matrix. The source block has to be
297-
# complete, such that the destination block has as many trees (`n`); the tree vector of a block
298-
# that is no longer needed can be passed on as `buffer`.
297+
# complete, such that the destination block has as many trees (`n`).
299298
struct TreeRows{F, D}
300299
trees::Vector{F}
301300
index::Union{D, Nothing} # `nothing`: few trees, the rows are found by a linear search
302301
n::Int
303302
# no default outer constructor, of which `D` would be unbound if `index === nothing`
304303
TreeRows{F, D}(trees::Vector{F}, index, n::Int) where {F, D} = new{F, D}(trees, index, n)
305304
end
306-
function TreeRows(::Type{F}, n::Int, buffer = nothing) where {F}
307-
trees = buffer isa Vector{F} ? empty!(buffer) : sizehint!(Vector{F}(), n)
305+
function TreeRows(::Type{F}, n::Int) where {F}
306+
trees = sizehint!(Vector{F}(), n)
308307
K = Base.promote_op(treeindex_data, F)
309308
index = n > 32 ? Dict{K, Int}() : nothing
310309
return TreeRows{F, Dict{K, Int}}(trees, index, n)

0 commit comments

Comments
 (0)