Skip to content

Performance issue on access Table with symbol not in function scope  #101

@waldie11

Description

@waldie11

How do I access allocation free AND flexible a TypedTable?

Nevermind the way quicker access at the NamedTuple.

using TypedTables
using BenchmarkTools

y = (a=1:1_000,)
x = Table(y)
v = zeros(eltype(getproperty(x,:a)),100)

#this fixes the column statically to label :a
function access_table!(v,x)
    for i in 1:length(x)
        v[i%length(v)+1] += getproperty(x,:a)[i]
    end
end
@btime access_table!($v,$x)
@btime access_table!($v,$y)

5.093 μs (0 allocations: 0 bytes)
4.200 ns (0 allocations: 0 bytes)

function access_table2!(v,x;label=:a)
    for i in 1:length(x)
        v[i%length(v)+1] += getproperty(x,label)[i]
    end
end
@btime access_table2!($v,$x)
@btime access_table2!($v,$y)

51.871 μs (2000 allocations: 62.50 KiB)
3.800 ns (0 allocations: 0 bytes)

function access_table3!(v,x::TypedTables.Table;label=:a)
    n = getproperty(columns(x),label)
    for i in 1:length(x)
        v[i%length(v)+1] += #= getproperty(x,label) =#n[i]
    end
end
@btime access_table3!($v,$x)

5.633 μs (2 allocations: 64 bytes)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions