I just want to add my vote of reiteration on the eliminating redundant db connections. I once inherited a cgi app that took forever to load - looking at the source, I realized that part of the speed problem was that there were more than a dozen db based items, all of them run independantly of the other. And the infamous "works fine in development" didn't cut it - dev only had 3 users, vs a few hundred thousand a day in the real world.
"I have never written bad code. There are merely unanticipated features."