Skip to content
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

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

Open
waldie11 opened this issue Sep 10, 2022 · 1 comment
Open

Comments

@waldie11
Copy link

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)

@waldie11
Copy link
Author

Got it...
Can there be done sth to help improve access natively? This does not sound like a job for AcceleratedArrays.jl, but I might be wrong.

using TypedTables
using BenchmarkTools

y = (a=1:1_000,)
x = Table(y)
v = zeros(eltype(getproperty(x,:a)),100)
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.320 μs (0 allocations: 0 bytes)
4.110 ns (0 allocations: 0 bytes)

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

4.230 ns (0 allocations: 0 bytes)
4.320 ns (0 allocations: 0 bytes)

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

No branches or pull requests

1 participant