I am creating my own method to create a graph in 3D because graphplot
has a bug, which I reported here and on Github, and I got no reply, and yet I still need the plot. Here is some MWE, which I run 2-3 times to make sure @time
provides approximately correct values. @btime
will not provide me with additional information in this case.
using LightGraphs
using GraphRecipes
import Plots
Plots.PlotlyBackend()
function plotGraph(graph, x, y, z)
edges_ = []
nb_nodes = nv(graph)
nb_edges = ne(graph)
p = Plots.plot([],[])
for e in edges(graph)
i = src(e)
j = dst(e)
xx = [x[i], x[j]]
yy = [y[i], y[j]]
zz = [z[i], z[j]]
if i == 1
p = Plots.plot(xx,yy,zz, color=:red)
else
Plots.plot!(p,xx,yy,zz, color=:red)
end
end
return p
end
const n = 1000
const graph = SimpleGraph(n, 3*n)
const x = rand(n)
const y = rand(n)
const z = rand(n)
@time const p = plotGraph(graph, x, y, z);
@time display(p)
I am simply displaying the graphâs edges. With a small graph with 1000 nodes and 3000 edges, the execution of my method, plotGraph
takes about 1.1 seconds (a factor of 2 or 3, either way, does not change the point I am making), while display()
takes about 19 seconds to complete and then another 20 seconds to actually see the plot!!! That is huge since I wish to display 100,000 edges. The time is incredibly high, and I am hoping not to have to use OpenGL
for this, which I abandoned 15 years ago!
Note that when I do not use constants, the memory allocation is about 800 Mbytes rather than 1.6 Gbytes, and the time is halved to 8 seconds, indicating that time is proportional to memory allocation.
So the question is: how is it possible to have so much memory allocation for such a small problem. It seems inconceivable to me. There is surely room for substantial speedups of this particular problem.
In 1986, I used the first Silicon Graphics, and although I was programming in C, I could easily draw 10,000 lines in real-time (10 frames per second), with almost no startup time. That is 35 years ago!!! I got faster speed even taking compiling into account. And even though it was C, this was 35 years ago and it was specialized hardware, computers of all stripes are so much faster today.