Revert "Revert "Performance increase in thumbnail handling""

This reverts commit e71baa3b8bb2ee5cff8d60fd6ff593bdc987abd4.