The last financial crisis was a good war for New York City. Next time may be different.

No one knows when the crisis will come. Global markets seem crazy, with $17 trillion worth of debt, nearly one-third of supposedly high-quality bonds, trading at negative interest rates. Investors, who are paying companies and governments, rather than being paid, to lend money, are expressing something, although they can’t decide what it is.

In the meantime, we can assess whether Gotham has taken advantage of the good times to prepare.

The 2008 meltdown didn’t feel lucky. New York saw nearly $3 billion in tax revenue vanish, more than 7 percent of its total annual take. Adjusted for inflation, revenue wouldn’t recover for three years. The city also lost 6 percent of private-sector jobs, more than 200,000.

But compared to the country, this was a success. The United States lost nearly 8 percent of jobs — and didn’t recover them until 2014, three years later than New York did. As for state and local tax revenues: As the Pew Trusts note, it took until 2013 for states, on average, to return to pre-recession peaks.

So New York didn’t see the service cuts and layoffs that made ­recovery worse elsewhere.

That’s partly because New York’s financial industry bounced back quickly, and that, in turn, was because of the extraordinary steps Congress and the Federal Reserve took to shore up failing banks. The securities industry, Wall Street, booked record profits in 2009. Last year, its $27.3 billion profit was higher, adjusted for inflation, than the $25.5 billion earned in 1999, another boom-era year, and higher, too, than the $27 billion in 2006.

Despite all the talk — and some reality — about “diversifying” New York from Wall Street by ­encouraging tech jobs and the like, New York still depends on Wall Street, because Wall Street has the cash.

As state Comptroller Tom ­DiNap­oli noted in March, the ­industry’s average salary (including bonus) is $422,500, more than five times higher than the private sector’s $77,100 average. Wall Street, with less than 5 percent of jobs, still less than the pre-recession peaks, creates more than 20 percent of private wages, something no industry can match.

With high-paying jobs come high taxes, and so the city will likely get 7 percent of its tax dollars from Wall Street this year, a percentage point higher than last year. That’s lower than the pre-recession peak, but it’s a lot — $4.2 billion.

Feverish markets have knock-on effects: One-fifth of the city’s $13.4 billion in personal income taxes comes from capital gains, profits from selling stock, and dividends — sources that disappear in a downturn.

In a downturn, the same percentage drop-off in taxes as last time would mean an instant $4.4 billion deficit, overwhelming the city’s $1.4 billion reserve. But the city already faces a $3.5 billion deficit next year; it is expecting good surprises, not bad ones.

It’s easier to increase spending than cut — workers will not give back bargained raises, and the city can’t cut back quickly on debt, pension and health care payments, which total nearly $30 billion annually.

Another fast recovery is hardly assured.

Nationally, there is no appetite for Wall Street bailouts. Locally, instead of a mayor who grasped the gravity of the situation, we have a mayor who is staging a one-man work slowdown.

Longer-term: The city owes nearly $150 billion for long-term ­retirement benefits for public ­employees — ­beyond what has been squirreled away in trust funds. Mostly because of these liabilities, New York City is, officially speaking, insolvent, with liabilities exceeding assets by ­almost $200 billion.

Now, the city’s population, growing a decade ago, may have plateaued, in part because we are up against what subways and streets can handle, absent better investment of boom-era dollars.

After the 2008 financial crisis, New York was still rebuilding from 9/11, maintaining construction employment. Now, the construction industry is shrinking, having shed 1,000 jobs in the ­second quarter. And new federal law has made it more difficult for the city and state to raise already high taxes.

New York had better hope the markets stay crazy, because sanity would be depressing.

Nicole Gelinas is a contributing editor of City Journal.