Closed AtiyahElsheikh closed 2 years ago
prioritize optimization potentials across all algorithms and not just findNewHouse()
I doubt that the compiler will insert caching of local variables across function calls, but I agree with you that a naive implementation is totally fine for now.
I just encountered a very similar problem during the implementation of marriages (length of age classes is needed for every single call to marriage!
). I think the easiest and least intrusive solution to both problems might be to use memoisation. It's not difficult to implement manually, but there's already a nice package that should do exactly what we need.
So, in your case you would for example memoise the function getEmptyHouses(houses)
. This would then compute the list of houses on the first call and afterwards just return it. There are two important things to keep in mind, though. First, the list of empty houses needs to be modified by the function calling getEmptyHouses
(as it's not going to be recalculated). And second, depending on what else happens in the simulation it might be necessary to clear the cache (using empty_cache!
) now and then.
I will have a look over it.
I was just thinking to have global typed variable(s) using the newest Feature of Julia 1.8.1 to be maintained every iteration. Not sure here if global typed variables still not recommended in the context of performance.
You can also just make it const, that should have the same effect, performance-wise (note that const in Julia just means no reassignment). Anyway, I think memoisation is the cleaner solution.
I think this is solved, marking for deletion.
Initially I have an impression that an optimal algorithm should maintain static lists of empty houses for each town to be updated by need. This would add an overhead to the implementation. First thoughts, this could be done either
My currently favorite approach is to follow the naive way without additional overhead efforts (i.e. set of empty houses are re-computed in every iteration) for the following reasons: