Website speed plays a role as it shapes user-experience. Google would like to see the desktop and mobile versions of websites load at about 2 seconds and users not dropping off for any reason. If speed is a reason visitors abandon the site, then the site will lose its first page rankings or will never reach the first page. Remember, the first page is only for the best. Website speed has been a ranking factor in Google since 2018.
So, a high bounce rate caused by lagging websites will have negative effects. Plus, Google may filter out the sites that lag in speed by not entering the first page. Not optimized images (size, compression), scripts that burden the page, different files that get pulled by the page, and are not merged into one, external fonts, old templates, many redirects, slow CDNs, coding formatting and comments, all these affect website speed. The issue is even more crucial on mobile devices. Remember, Google runs the mobile index as primary. If the mobile version is slow, good rankings are over. My take is user experience is more important than Google. If you lose visitors at the entrance, nothing can be done even if you're on the first page. Google recommends offering an AMP version of your pages and using Google PageSpeed Insights as a tool to optimize your speed.