JuliaArrays / JuliaArrays/StaticArrays.jl

SVector sometimes allocates

Open
#1,015 4 comments 0 reactions 0 assignees View on GitHub

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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.