@Noah111 can you confirm which Device you have, if S9+ a device of that age increasingly likely to run into issues. Clearing the cache partition for instance can generally help with lags/freezes but may be a deeper issue. If unaware follow these steps:
1. Turn off the device.
2. Connect To Computer , other Device or TV USB, Press and hold the Volume Up key and then press and hold the Power key
3. When the Android logo displays, release both keys.
4. Wait until the Android system recovery menu options appear.
5. Press the Volume down key several times to highlight wipe cache partition.
6. Press Power key to select.
7. Press the Volume down key to highlight yes, them and press the Power key to select.
8. When the wipe cache partition is complete, Reboot system now is highlighted.
9. Press the Power key to restart the device.
Restarts (not scheduled) can sometimes be caused by conflicts with 3rd party apps. If ok in Safe Mode would pinpoint recent 3rd party apps which have been installed.
https://www.samsung.com/uk/support/mobile-devices/how-to-start-my-galaxy-device-in-safe-mode/The S9 series also stopped receiving security updates in 2022 and thus vulnerability increases (if this is relevant)
https://eu.community.samsung.com/t5/other-galaxy-s-series/s9-software-update/td-p/11987593
I do not work for Samsung or make Samsung Products but provide independent advice and valuable contributions.