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

improve performance of setindex! on IdDict #33009

Merged
merged 2 commits into from
Aug 23, 2019
Merged

Conversation

KristofferC
Copy link
Sponsor Member

The benchmark run of 1.3 vs 1.2 showed some performance regressions for IdDict. Profiling, it seems that the convert call now goes through jl_apply_generic:

              123 ./abstractdict.jl:479; push!
               62 ./abstractdict.jl:582; setindex!(::IdDict{Int64,Int64}, ::Any, ... # <--- convert call
                46 ...kristoffer/julia/src/gf.c:2296; jl_apply_generic
                 37 ...kristoffer/julia/src/gf.c:2247; jl_lookup_generic_
                  36 ...ia/src/./julia_internal.h:939; jl_typemap_assoc_exact
                   11 ...ffer/julia/src/typemap.c:850; jl_typemap_level_assoc_exact
                    3 ...ffer/julia/src/typemap.c:255; mtcache_hash_lookup
                     3 ...ffer/julia/src/typemap.c:186; jl_intref
                      3 ...fer/julia/src/./julia.h:802; jl_svecref
                    3 ...ffer/julia/src/typemap.c:269; mtcache_hash_lookup
                   21 ...ffer/julia/src/typemap.c:851; jl_typemap_level_assoc_exact
                    20 ...a/src/./julia_internal.h:935; jl_typemap_assoc_exact
                     4 ...ffer/julia/src/typemap.c:803; jl_typemap_entry_assoc_exact
                      2 ...fer/julia/src/typemap.c:123; sig_match_simple
                     6 ...ffer/julia/src/typemap.c:816; jl_typemap_entry_assoc_exact
                      2 ...fer/julia/src/typemap.c:136; sig_match_simple
                       1 ...fer/julia/src/./julia.h:1127; jl_is_type_type
                       1 ...fer/julia/src/./julia.h:1128; jl_is_type_type
                10 ...a/usr/lib/julia/sys.dylib:?; jfptr_convert_4167
                 7 ...ffer/julia/src/datatype.c:724; jl_box_int64
                  4 ...ia/src/./julia_internal.h:233; jl_gc_alloc_

Workaround this by only calling the convert when it is not known to be a no-op.

With

function perf_push!(c, elts)
    for e in elts
        push!(c, e)
    end
end

elts = [rand(Int) => rand(Int) for i in 1:100]

The relevant benchmarks are:

1.2

@btime perf_push!(IdDict{Int,Int}(), elts)
#  11.889 μs (206 allocations: 11.48 KiB)

@btime perf_push!(IdDict{Any,Any}(), elts)
#  12.150 μs (206 allocations: 11.48 KiB)
Master
@btime perf_push!(IdDict{Int,Int}(), elts)
#  20.218 μs (306 allocations: 13.05 KiB)

@btime perf_push!(IdDict{Any,Any}(), elts)
#  13.461 μs (206 allocations: 11.48 KiB)

PR

@btime perf_push!(IdDict{Int,Int}(), elts)
#  11.182 μs (205 allocations: 7.36 KiB)

@btime perf_push!(IdDict{Any,Any}(), elts)
#  11.121 μs (205 allocations: 7.36 KiB)

@KristofferC KristofferC added the performance Must go faster label Aug 21, 2019
@KristofferC
Copy link
Sponsor Member Author

@nanosoldier runbenchmarks("collection", vs = ":master")

base/abstractdict.jl Outdated Show resolved Hide resolved
@nanosoldier
Copy link
Collaborator

Your benchmark job has completed - possible performance regressions were detected. A full report can be found here. cc @ararslan

@KristofferC
Copy link
Sponsor Member Author

Performance looks good but would be good to know if the now dynamic call to convert is expected, cc @vtjnash, @JeffBezanson .

@JeffBezanson JeffBezanson merged commit d1979e3 into master Aug 23, 2019
@JeffBezanson JeffBezanson deleted the kc/setindex_iddict branch August 23, 2019 14:58
KristofferC added a commit that referenced this pull request Aug 25, 2019
@KristofferC KristofferC mentioned this pull request Aug 25, 2019
36 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance Must go faster
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants