I just want to amend this thread by adding that recently, on a nearly daily basis, the sitemapgenerator task has been "freezing up" and not completing. I am not wanting to create a ticket for this issue, but want to see if anyone else is having this issue.
Sometimes the "Run Now" will work, but other times I need to go into the Task Manager area and stop the task, then run it. I've tried rebuilding the sitemap a few times, but the issue keeps happening, at least 3-5 times a week now.
I suspect (but can't prove) that the changes in the code that you made to the sitemap is causing both issues mentioned in this thread--the excessive resource usage (which I believe is triggered by this task), and now task failing, and sometimes getting stuck running for 8+ hours.