I use Drupal 8, search API and a search view with infinite scroll (10 results per page). In a header field I display the number of search results with @total. Unfortunately, @total is always a maximum of 10, even for searches that should actually have 500 hits.
To determine the correct number of search results, I did the following in a custom module
function my_module_views_pre_render(ViewExecutable $view) {
  if ($view->id() == 'myview' ) {
    /*
     * calculate proper number of search results with a tmp view
     */
    $view2 = Views::getView('myview');
    $view2->setDisplay('page_1');
    $view2->setItemsPerPage(10000);
    $view2->execute();

    $view->total_rows = count($view2->result);
  }
}
That works fine. But with about 2000+ existing nodes the performance is very bad.
Is there a better way to determine total_rows?
I am grateful for every tip