The 8 GB of RAM and a 5400 rpm hard drive are not good specs for running Xcode.
I have a similar model of iMac with 16 GB of RAM and Xcode on an external SSD, and Xcode 14.2 runs decently. It's not blazing fast, but it's not painfully slow either.
If your iMac is a 27 inch model, you can add RAM to it. Doing that and moving your boot drive to an external SSD will improve things.
Topic:
Developer Tools & Services
SubTopic:
Xcode
Tags: