I wouldn’t rule out hardware.
Did you build the machine yourself?
Are there any old or well-used components in the build?
It might be good to start working through TBG’s checklist to see if you can put together more troubleshooting info to comb through: Troubleshooting System Stutter, Lags, Freezes, and Hangs - #11 by tbg
Here is a bit more material to plough through at your leisure: Troubleshooting System Stutter, Lags, Freezes, and Hangs
This is a relatively tame contribution from me I’m afraid; TBG wrote the essay.