Problem is the same as
It's impossible create template full clone (if there is LLD).
The problem is that it eats up too much memory more than 2GB.
Changed (in /zabbix/include/classes/api/services/CDiscoveryRule.php:1137):
While loop eats less memory, then foreach.
With this solution we achieved that full clone does not eat up memory (and stop crashing), but the cloning process still is taking very long time (you may need to increase execution time).
For us this is problem to clone templates in large system.