Jamie – good news! Richard has found the cause of the problem. It was an error I had made when converting his original (webtrees) code to use in kiwitrees. I had broken the important /necessary relationship caching feature 🙁
Attached is a replacement for the file kiwitrees/includes/functions/functions.php which fixes the problem.
My results for your complex relationship is now:
Execution time: 1.593 seconds. Database queries: 644. Privacy checks: 290. Memory usage: 18,432 KB