Try the following in order as needed;
1 - launch your library with the Option+Command keys held down and repair the library. Then test to see if the problem persists.
2 - boot into Safe Mode according to How to use safe mode on your Mac and test to see if the problem persists. Reboot normally and test again.
NOTE: Safe Mode boot can take up to 2 - 3 minutes as it's doing the following;
• Verifies your startup disk and attempts to repair directory issues, if needed
• Loads only required kernel extensions (prevents 3rd party kernel/extensions from loading)
• Prevents Startup Items and Login Items from opening automatically
• Disables user-installed fonts
• Deletes font caches, kernel cache, and other system cache files
Note: if you have a wireless keyboard with rechargeable batteries connect it with its charging cable before booting into Safe Mode. This makes it act as a wired keyboard as will assure a successful boot into Safe Mode.
3 - as a test launch Photos with the Option key held down and create a new, test library. Import some photos and test to see if the same problem persists. Does it? If not then close the test library, open your primary library and test again.
Have you installed and run any "cleaning", "optimizing", "speed-up", anti-virus or VPN apps on your Mac?