So here’s some perspective: My entire home country has 6 Michelin star restaurants. Of those, 1 is in the capital which is the home town I’m comparing above.
SF has 7 restaurants with 3 stars.
Places with stars don't have the economic situation I discussed: they have the money to really go beyond their surroundings.
The competition means that a lot of places scraping by in smaller cities can’t make it in a bigger city. In theory that means median quality is higher.
And even a 3-star restaurant won’t survive in a place that doesn’t get enough well-to-do visitors to sustain it.
For a more casual perspective, SF has 126 restaurants on the Michelin list (not all hve stars). My entire home country has 52.
Quality food has more to do with agriculture and supply chains than money or density per se -- good salad is not something you can buy if no one is growing it -- and more and more areas in the US have made the transition to that kind of farming and production.
Now challenging SF on grocery stores -- that's another matter. They are drawing on deep roots, there.
There are exceptional cuisine resources in San Francisco, and amazing grocery stores, like Bi-Rite and Rainbow, but as a whole the situation neither benefits from the culinary community that it used to have (how many people have moved away) or from the kind of consumer that it used to have (well to-do kids just out of Stanford or a midwest school are not people who know what buffalo mozzarella is, or why you'd want to buy it, but their money rapidly became the only money that mattered).