bestCommittedRunNumber resolution currently re-filters and re-sorts srcRuns for every driver (srcRuns.filter(...).sort(...)). Since srcRuns is already ORDER BY id, the sort is redundant, and the repeated filtering is O(drivers*runs). Consider pre-grouping srcRuns by driver_id once (you already build runsByDriver later) and reusing that list to compute the committed index.
bestCommittedRunNumberresolution currently re-filters and re-sortssrcRunsfor every driver (srcRuns.filter(...).sort(...)). SincesrcRunsis alreadyORDER BY id, the sort is redundant, and the repeated filtering is O(drivers*runs). Consider pre-groupingsrcRunsbydriver_idonce (you already buildrunsByDriverlater) and reusing that list to compute the committed index.