JuliaArrays / JuliaArrays/StaticArrays.jl
SVector sometimes allocates
Open
Nobody has claimed this yet.
- Dominant language
- Julia
- Stars
- 844
- Forks
- 159
- Avg merge
- 3d 21h
- Merged PRs (30d)
- 3
Description
This does not allocate
const v=[1]
const vl=length(v)
function g()
SVector{vl, Int}(v)
end
@timev g()
0.000001 seconds
elapsed time (ns): 769
gc time (ns): 0
bytes allocated: 0
pool allocs: 0
non-pool GC allocs: 0
minor collections: 0
full collections: 0
But this allocates:
const v=[1]
function g()
vl=length(v)
SVector{vl, Int}(v)
end
@timev g()
0.000017 seconds (10 allocations: 528 bytes)
elapsed time (ns): 17108
bytes allocated: 528
pool allocs: 10
1-element SVector{1, Int64} with indices SOneTo(1):
1
julia> @allocated g()
528
Using @SVector is not an option for me due to #1014
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the two g() examples from the issue in Julia, comparing @timev and @allocated when vl is a constant versus a local length(v) value. Trace the SVector{vl, Int}(v) construction and inspect issue #1014 for the stated constraint; done means the local-length form no longer incurs the reported allocations without relying on @SVector.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- julia
- Domain
- performance
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100