I will also add a WITH SCHEMABINDING
to the TVFN so SQL Server can parallelise the plan. While we're on this subject, the using a multi-statement table-valued function is a good idea (Thank you to Paul WhitePaul White), but multi-statement TVFN's always force a serial plan.
I will now try Lennart's answeranswer, in which he suggested using a CTE.