This is almost always a case of a programming language loop that implicitly does..
begin transaction
delete from history where id = @id
commit
.. on every iteration. Which is asking the storage engine to write the new data and make sure it's flushed to disk between each deleted entry. No wonder it's slow. You can get massively better just by hoisting the transaction begin and commit to outside the loop, and even better if you can drop the loop altogether and specify range of entries to delete directly.