You may use the hammerstone/fast-paginate package. The theory for this feature can be found here.
You need to override the paginateTableQuery method. This should be on your Livewire component class. If you're using a panel resource, the Livewire component is your List or Manage page (in the /Pages directory of the resource). If you're using a panel relation manager, this class is the Livewire component.
use Illuminate\Contracts\Pagination\Paginator;
use Illuminate\Database\Eloquent\Builder;
protected function paginateTableQuery(Builder $query): Paginator
{
return $query->fastPaginate(($this->getTableRecordsPerPage() === 'all') ? $query->count() : $this->getTableRecordsPerPage());
}