Thumb() running very slowly?

I moved my Kirby install to a new server. One page seemed to load incredibly slowly (over a minute) and sometimes failed or got stuck in an infinite loop. Eventually, I narrowed it down to this line of code, which crops an image to a square:

<img class="work_image" src="<?=thumb($item->image(), array('width' => 300, 'upscale' => true, 'crop' => true))->url();?>" width="300" height="300" /><br />

I replaced this line with:

<img class="work_image" src="<?=$item->image()->url()?>" width="300" height="300" /><br />

And used CSS to crop the image properly:

img.work_image  {
  object-fit: cover;

However, this is unsatisfactory, as the native browser resizing of the image is much lower quality than the Kirby resizing.

Does anyone know why thumb() might be stalling like this? What subprogrammes is it calling? Can I install something on my server to make it run fast again?