I've been toying around with the new Swift Package Manager a bit and found that I'm unable to garner the performance that I would expect and trying to identify if I’ve made an error in my understanding or design.
Initially, I was working on a rudimentary flood fill algorithm and found that I could break it apart into multiple Swift modules and thought this would be a grand time to try out the new SPM. :-)
I created a `Stack`, `FloodFill`, and `FloodFillApp` module. The FloodFill module depends on the Stack module, and the FloodFillApp application then calls upon the FloodFill module to perform the algorithm. Very linear, quite simple. Prior to breaking it into separate modules the algorithm was taking around 0.04s to complete. Upon breaking it apart into separate modules and then compiling the FloodFillApp using `swift build -c release` I found that suddenly the algorithm was completing in around 16s! If left in debug mode, it takes around 120s to finish.
The only thing I can come up with is that the `-whole-module-optimization` doesn’t cross these interdependent module boundaries and therefore can’t identify the same optimizations, leading to worse performance. I just didn’t quite expect such a remarkable contrast. Of course, this is just speculation. The only solid evidence I have supporting this is that when I copy the files from the other two modules into the FloodFillApp (and obviously remove dependencies/imports/etc), the performance returns to 0.04s.
Is there a way I can improve this performance and still maintain separate modules? Other thoughts?