A lot of 3G owners have suffered from extremely slow performance with the 4.0 upgrade. Fortunately, Lifehacker has a great article explaining how to downgrade your iPhone 3G[S] from iOS 4.0 to iOS 3.1.3.
Lifehacker – How to Downgrade Your iPhone 3G[S] from iOS 4 to iOS 3.1.3
I just tried this last week and it worked perfectly. I can finally use my phone again!