The vault location could be a factor, but vaults in OneDrive tend to behave as long as everything is set to be local and stays that way — though my vault in OneDrive is nowhere near 40k files.
One quick and easy test you could do is turn ON Restricted mode and restart. If things seem better, turn Restricted mode OFF and disable all your community plugins. Restart. Enable one-at-a-time, with restarts/reloads in between turning one on, and you’ll see the general startup time slowing down. Maybe you can narrow it down to one or two plugins causing most of the hang-up.
Other troubleshooting steps are here: