Skip to content

Improve deleteat!(x,::Integer) #117

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

laborg
Copy link
Contributor

@laborg laborg commented Dec 25, 2024

We only need to remove one element from a ChainedVector and can therefore special case the fact that if this element is a single entry in a chunk the chunk can be removed completely. This reliefs us from the slow cleanup!() call.
As a result dependent functions performance improve:

pop!() with many chunks

julia> function popall(x)
           while length(x) >0
               pop!(x)
           end
       end
popall (generic function with 1 method)

julia> popall(ChainedVector([[1]])); # compilation

julia> cv = ChainedVector([rand(Int,5) for _ in 1:20000]);

julia> @time popall(cv) # main
  1.043174 seconds

julia> @time popall(cv) # pr
  0.003701 seconds

popfirst!() with many chunks

julia> function popall(x)
           while length(x) >0
               popfirst!(x)
           end
       end
popall (generic function with 1 method)

julia> popall(ChainedVector([[1]])); # compilation

julia> cv = ChainedVector([rand(Int,5) for _ in 1:20000]);

julia> @time popall(cv) # main
  1.423213 seconds

julia> @time popall(cv) # pr
  0.128358 seconds 

popfirst!() with single chunk

julia> function popall(x)
           while length(x) >0
               popfirst!(x)
           end
       end
popall (generic function with 1 method)

julia> popall(ChainedVector([[1]])); # compilation

julia> cv = ChainedVector([rand(Int,100000)]);

julia> @time popall(cv)
  0.002024 seconds # main

julia> @time popall(cv)
  0.001135 seconds # pr

We only need to remove one element from a ChainedVector and can therefore special case the fact that if this element is a single entry in a chunk the chunk can be removed completely. This reliefs us from the slow `cleanup!()` call.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant