MRC-CSO-SPHSU / UKSEABMLib.jl

MIT License
1 stars 1 forks source link

Performance improvement #31

Open AtiyahElsheikh opened 1 year ago

AtiyahElsheikh commented 1 year ago

potential performance improvement by a variety of ways:

AtiyahElsheikh commented 1 year ago

[ ] getting rid of the use of global variables Debug instructions within simulation functions  #20

When disabling the macros for doDeaths! performance improves between 10-25%. But checking the underlying code, it is possible that another issue is causing this performance drop.

AtiyahElsheikh commented 1 year ago

[x] MultiAgents.jl (existing potential type instability)

Employing version 0.4 of MultiAgents.jl brought 15-25% runtime and memory performance improvement

AtiyahElsheikh commented 1 year ago

Initial efforts show that this brings significant improvement in memory consumption due to less temporary arrays are created each iteration.

AtiyahElsheikh commented 1 year ago

[ ] getting rid of the use of global variables Debug instructions within simulation functions  #20

Isolating debug and assumptions checking in separate code and at a level not extensively executed (e.g. dodeaths rather than deaths!) seem to impact the performance positively

AtiyahElsheikh commented 1 year ago

[ ] make outputs of simulation function become an argument (of type struct)

Functions s.a. doDeaths and doBirths create arrays of references every iteration. Avoiding this seems to significantly improve the memory usage and performance. This has been initially realised as described in #29.

AtiyahElsheikh commented 1 year ago
  • Make type Person a concrete type #37

Corresponding fix improves memory allocation by c.a. 30%

AtiyahElsheikh commented 1 year ago

[ ] improve implementation of allocation to other houses Improving implementation o movePeopleToEmptyHouse #23

  • [ ] improve implementation of finding empty houses,
  • [ ] investigate if it is worth to make related functions, e.g. select_house return only one type

This part has led to significant improvement due to reduced usage of temporary arrays. For an idea, executing version 0.2.5 with an initial population of 5000 (i.e. 10000 man and women), performance looked as follows:

V0.2.5: 20.237322 seconds (154.70 M allocations: 7.828 GiB, 3.65% gc time)

After improvement

7.653553 seconds (37.11 M allocations: 2.194 GiB, 2.75% gc time)

The improvement was also due to replacement of memoization in doMarriages function.

AtiyahElsheikh commented 1 year ago

[ ] investigate if it is worth to make related functions, e.g. select_house return only one type

I am not sure if improving this has contributed to the performance improvement

AtiyahElsheikh commented 1 year ago
  • the usage of memoization in do_marriages #40

As expected, it turned out that the more natural approach is more efficient in terms of memory and runtime. In this particular case, it seems memoization was consuming alot of storage (or may be it is not properly implemented).

AtiyahElsheikh commented 1 year ago

after Version 0.3