Maybe making TInd immutable here would be sensible unless you need to directly modify the fields of it a lot. Even then it would probably be faster to just swap it out for a new TInd with the new fields. That way you can store the whole vector as a contiguous block of memory.
On Monday, September 7, 2015 at 7:55:16 PM UTC+2, Cedric St-Jean wrote: > > Do you ever modify an individual? If not, why not just write > > world[p].ind = newpop > > Also, did you profile to make sure that deepcopy is the bottleneck? If > your structures are that simple, it's surprising to me that deepcopy is > taking a long time. > > Cédric > > On Monday, September 7, 2015 at 1:08:50 PM UTC-4, [email protected] > wrote: >> >> Hello everybody, >> >> I'm comparably new to Julia, but not completely new to programming. Yet, >> I'm a biologist by training, so please excuse potentially dumb questions in >> advance :) >> >> I am working in evolutionary ecology, programming individual-based >> simulations. I have now transferred a (very) simple program that simulates >> insect populations into Julia and am so far happy with its performance and >> style (I really fell in love with Julia). Yet, I do have a performance >> problem when it comes to copying a complex object. First of all my basic >> type structure: >> >> type TInd # an individual >> ld::Float64 >> disp::Bool >> end >> >> type TPop # a single population >> ind::Array{TInd,1} >> end >> >> world = TPop[] # just to mention, this is NOT a global variable, but in >> my main simulation function to create multiple populations >> >> You see that I have a set (world) of populations (TPop), each being >> defined as arrays of individuals. During reproduction, I create a second >> Array of individuals, that stores the (mutating) offspring. So far so good. >> Yet, since I assume discrete generations, after each individual in a >> population has reproduced, the parental population is to be replaced by the >> offspring. I have implemented that like this: >> >> newpop = TInd[] >> >> # ... then the new population gets filled with offspring ... >> >> world[p].ind = deepcopy(newpop) >> >> Of course, this solution is working, but it is really slow. And since I >> do actually not need a copy of the newpop, but just want it to overwrite >> the original population, I guessed there might probably be a faster and >> more elegant solution (without complex workarounds, just somehow adjusting >> the pointers!?)? From what I've seen the model will probably run faster >> than in C++ as soon as I find the answer :))) >> >> I appreciate any help, thanks a lot in advance! >> >> All the best, >> Alex >> >
