Skip to content

performance of Ref #11531

@StephenVavasis

Description

@StephenVavasis

I have pointed this out in a discussion of my pull-request on DataStructures.jl, and I also submitted a related documentation issue, but maybe it should be a Julia issue too. For the function

function testref1(m)
    a = [3.0, 4.0, 5.0]
    sm = 0.0
    for i = 1 : m
        q = Ref(a,1)
        sm += q[]
    end
end

I get the following timing result:

julia> @time testref.testref1(100000000)
   1.012 seconds      (100 M allocations: 3052 MB, 16.17% gc time)

Notice the huge memory allocation. The reason is that the object q is allocated on the heap rather than the stack. This behavior suggests that Ref(array,index) should not be used in an inner loop of a high-performance code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions