ArchiveProcessor::aggregateDataTableRecords counts by default the number of rows recursive. I noticed this takes a lot of time especially on large dataTables: https://github.com/piwik/piwik/blob/2.12.0-b7/core/ArchiveProcessor.php#L220
We're calling this method 17 times but it is only actually used once. Therefore I added a parameter to disable it (not enabled by default to stay BC. I failed to find a better solution. Only solution I could think of alternatively would be to add another method that does not count recursive.
In the following example run you can see that it takes 13.5 seconds (with xhprof and only no_builtins flag) which is 15% of the total time to get the rows count recursive. And this is only for 5 records. Those 17 calls easily make 30 records. Meaning we will save a lot of time when generating week, month, year and range archives.