First, NYC is also kind of a clusterfuck; rents there are terrible. But while NYC needs to continue building more, it at least has the excuse that it's built up a lot already, and its mayor is actively encouraging more development.
People don't cram into arbitrarily small spaces, so one thing to remember is the cause and effect: way more than 840K people want to live in SF proper, but there's no room. So 376K housing units effectively sets the population cap. But because a larger pool of people want to live there, the prices all go up. Rent control fixes that for incumbent residents but worsens the problem for everyone else. The only way to alleviate that is to create more houses so that a larger percentage of the people who want to live there actually can.
The subways in New York help the common case - minimizing how much is needed to spend on housing, while being well-connected to Manhattan. This is how people can live in a relatively cheap borough like Queens, and still have 15-35 minute commute to their job.
There's also a massive amount of rental apartment stock at any time. This means that you have the liquidity to make any tradeoffs necessary, by balancing your budget, commute distance, number of roommates, and the amount of space you need.
New York is also connected to several public transit systems (NJTransit, Metro North, PATH), so you can often go way cheaper, by leaving the city bounds itself.
It's not all sunshine and roses, though. Rent is going up in a lot of the previously-cheap neighborhoods in Brooklyn. This hasn't really affected me, but my sister has been priced out of multiple apartments in the 5 years she has lived in the city.
In a city with a population of 840K, is that so bad? That works out to roughly 2.23 people per unit.
In NYC, in 2011, there were 3.35M housing units, and population of NYC was 8.273M. That works out to 2.47 people per unit.
So why is NYC's situation not a clusterfuck, but SF's is?