sbromberger / MetaGraphs.jl

I never metagraph I didn't like.
Other
94 stars 24 forks source link

Improve performance of `get_prop` #123

Closed serenity4 closed 3 years ago

serenity4 commented 3 years ago

Before this PR, accessing a property on a vertex or on an edge was quite slow:

julia> using MetaGraphs, BenchmarkTools

julia> g = MetaDiGraph(2)
{2, 0} directed Int64 metagraph with Float64 weights defined by :weight (default weight 1.0)

julia> set_prop!(g, 1, :name, "one")
true

julia> @btime get_prop($g, 1, :name)
  85.547 ns (4 allocations: 512 bytes)
"one"

This was due to a PropDict being constructed every time get_prop was called, even if the key existed. Deferring this creation only to cases where the key was not present offered a nice speedup:

julia> using MetaGraphs, BenchmarkTools

julia> g = MetaDiGraph(2)
{2, 0} directed Int64 metagraph with Float64 weights defined by :weight (default weight 1.0)

julia> set_prop!(g, 1, :name, "one")
true

julia> @btime get_prop($g, 1, :name)
  9.117 ns (0 allocations: 0 bytes)
"one"

I also addressed these same performance issues for the undirected MetaGraph and for edge properties.

matbesancon commented 3 years ago

I'll try to finish #124 to get GH actions and documentation again before merging this, but looks good

matbesancon commented 3 years ago

@serenity4 can you merge master into your branch? Then we can see if all good on CI side

codecov[bot] commented 3 years ago

Codecov Report

Merging #123 (a72e551) into master (f52cbe4) will not change coverage. The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #123   +/-   ##
=======================================
  Coverage   98.64%   98.64%           
=======================================
  Files           5        5           
  Lines         368      368           
=======================================
  Hits          363      363           
  Misses          5        5           
Impacted Files Coverage Δ
src/MetaGraphs.jl 99.55% <100.00%> (ø)
src/metadigraph.jl 97.43% <100.00%> (ø)
src/metagraph.jl 97.72% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update f52cbe4...a72e551. Read the comment docs.