mod/folder/download_folder.php is consistently one of the longer running outrider processes.
There is a few things it could do better:
1) Getting to this page should be a get not a post (also improves web analytics)
2) write_close the session fairly early
3) opt in a a candidate for read only sessions
MDL-58018 (might be ruled out because of blocks)
4) the zip is blindly compressing everything which is an expensive mistake. Most files like audio / video / images and many office docs, ie 95% of what gets put into the mod_folder, are already compressed and so compressing these binaries again churns a lot of cpu and time for very limited compression, typically 1% - 2%. These files should be just appended to the zip file as is.
5) stream the zip downloading MDL-68533 so we never touch temp disk, and the TTFB is near instant
6) there is a bunch of heavy zip processing which could be done async ahead of time, and then the file download itself is a normal plugin file urls and not a post. So this zip file cannot benefit from any file system / object storage serving, including download pausing / resuming.
We'd need some mod_folder event stuff to rebuild the zip if the contents change, if someone tries to download the file in the mean time it could be rebuild on the file but that can be done using a progress bar for the zipping part, and then a normal plugin file url at the end once the progress bar is done, ie a button + reload / redirect to download.
The rebuilding event / ad hoc task can be throttled so it doesn't run immediately:
This will consume a lot of disk so is a trade off of speed vs storage. I'd only do this depending on much impact steps 4 and 5 have.