I called Los Angeles home for six years and now, as I bid goodbye, I sift through memories that feel incompatible, discordant.

There was the endlessness of the city, horizons of concrete, as you fly into LAX. New skyscrapers rising over downtown. Dolphins leaping in the surf off Malibu. Hustlers and dreamers and visionaries inventing things, making movies, mega-mansions, plans for Mars.

And Barbara, munching her sandwich.

I’ll start with Barbara. I don’t know her real name. Tiny, wiry, black curly hair falling to her shoulders, grubby face, grubby clothes, she looks about 45. She hobbles – a gammy left knee, I think. She doesn’t answer questions or really speak except to say “Br-br”.

She frequents Santa Monica Public Library, where I sometimes write. There’s a lovely courtyard with dappled sunshine and a little cafe. Local residents and tourists lunch there. So does Barbara.

Hauling plastic bags and a backpack, she limps in, resembling a pixie that fell down a chimney, lays her load in the middle of the yard. Then sinks bare arms inside a circular metal bin, rummages amid crumpled, gooey trash, extracts the remains of sandwiches and stands there, munching.

Other diners look away, look back, try not to stare. They sip their juices, continue chatting, unsure how to respond to this scene of human degradation. After six years I still feel that way.

A police car stops beside tents on Skid Row in Los Angeles. Photograph: Robyn Beck/AFP/Getty Images

How do you respond to a city of natural and human wonders, a city pulsing with energy, ambition, creativity, money – dear lord, so much money – which simultaneously hosts in-your-face squalor?

It’s ubiquitous, the grimy tents of downtown’s Skid Row replicated in mini-encampments from the San Gabriel mountains to Venice. Sleeping bodies slumped in doorways, on sidewalks, on beaches. Parked cars and camper vans filled with yet more people who have lost their homes.

Yet I love LA. I love it and will miss it.

It offers the best of America. A kaleidoscope of humanity – more than 200 languages – jumbled into Chinatown, Koreatown, Little Armenia, Little Ethiopia, Little Tokyo, Boyle Heights, Lincoln Heights, Pasadena, Palisades. Innovation and industriousness. Tolerance and laid-backness. All bathed in golden sunshine.

I’m struggling to reconcile the city I love with the wretchedness

Arriving in 2012, I liked the place straight away. Instead of horror at the tangled freeways and the vast, urban amorphousness I thought, wow, it works. California’s wild, beating heart thudded to a rhythm. Its geography and infrastructure made sense, it had rules and systems and norms, it felt safe and shiny.

Low expectations helped. I was coming from Caracas, Venezuela’s anarchic, grimy capital, and had braced for more of the same.

LA, after all, had long inspired dystopian fiction. And scorn. “Seventy-two suburbs in search of a city,” Dorothy Parker reputedly jeered. “Tip the world over on its side and everything loose will land in Los Angeles,” said Frank Lloyd Wright.

My timing seemed inauspicious. California verged on bankruptcy. “California is so broke that Mexico fixed the hole in the fence to keep us from crawling back in again,” Jay Leno joked. “California is so broke that I saw a going-out-of-business sign at a meth lab.”

But the story turned out to be one of a state, and city, on the rebound.

Arnold Schwarzenegger, the hapless Governator, gave way to a wily, effective successor, Jerry Brown. Voters backed a tax hike to balance the books. The real estate market recovered and Silicon Valley boomed. By 2013, California’s economy was humming – growing faster than the US average – and turning a $27bn deficit into a surplus.

“Word of California’s demise was greatly exaggerated,” Brown told me that year. “California is the healthiest it’s been in more than a decade.”

Chuck McCarthy, a ‘people walker’, walks with Rory Carroll in the Hollywood Hills. Photograph: Noah Smith/The Guardian

Public pensions and a lopsided tax system are ticking fiscal time bombs but the golden state continues thriving. This year, it overtook Britain to become the world’s fifth-biggest economy, with a GDP of $2.7tn.

LA drives much of it. Hulu and Netflix are reshaping the entertainment industry while Google, YouTube, Snap and other tech giants expand campuses across Silicon Beach. New bars, cafes, restaurants and condos are reviving the husk that was downtown.

Voters approved $120bn for investments in transport, one of the most ambitious public works in US history, expanding bicycle lanes and rail networks, threading the city together.

It’s not just the economy and infrastructure. LA, once a cauldron of gangs, racial animosity and brutal policing, has recorded dramatic drops in crime and tension.

“I tell myself time heals. It really does,” Rodney King told me. That was in April 2012, shortly before he died, still damaged by the beating he endured in 1991. The LAPD still shoots too many people, especially black people, but is today a reformed, accountable force with fewer jackboots.

Voters approved a ballot initiative to reduce penalties for drug and other non-violent crimes, helping to end one of America’s most notorious tough-on-crime experiments. They also legalised pot.

You don’t need to smoke it to sense a la-la vibe.

“We’re a place that reimagines tomorrow and reinvents today,” the mayor, Eric Garcetti, rhapsodised last year when LA clinched the 2028 Olympic Games.

The bride takes a hit at a marijuana-themed wedding in Carmel, California. Photograph: Robert Gumpert/The Guardian

This is largely true. Startups are inventing products and services that they hope will avert environmental disaster – prompted in part by LA’s alarming warming – and yield business models replicable around the globe, even beyond.

“We would welcome opportunities for off-planet growing,” Brandon Martin, vice-president of a company that turns shipping containers into hydroponic farms, told me. “We’d love to be the first company to grow food on Mars.” He was completely serious.

Elon Musk was equally bullish about colonising Mars when I interviewed him in 2013. These days, Iron Man is showing some rust. When I recently returned to SpaceX’s headquarters it was to interview people buying Musk’s flamethrowers, a publicity stunt underlining how the entrepreneur has veered off course.

Concerns about trolling, privacy intrusion and rewired brains have put a big, neon warning sign over other tech companies here claiming to make the world a better place – a bromide on par with Hollywood guff about elevating humanity.

Still, LA is fun to cover.

It’s a city of tribes, some inspiring, like the underground cycle gangs that reclaim streets from cars, or the artists transforming a desert ghost town, or the underemployed actors who moonlight as “people walkers”. Some are easy to ridicule, like the devotees of Gwyneth Paltrow’s Goop store, which peddles vampire repellent and sex dust. Others are intriguing but obnoxious, like the thuggish surfers at Lunada Bay.

And there is the brash plutocracy. I did a story in 2017 about a Bel-Air mansion listed for $250m, America’s most expensive home, only to do another in March about one listed for $500m – a 105,000 sq ft glass and marble behemoth with moats, four swimming pools, 20 bedrooms, a nightclub, a bowling alley, a cinema and walls and ceilings made of jellyfish aquariums.

Artists transformed a desert ghost town in Salton Sea, California. Photograph: Dan Tuffs/The Guardian

It made for good, breezy copy. But I didn’t feel good or breezy writing it from Santa Monica Public Library.

I didn’t see Barbara that day but the library was, as ever, packed with homeless people. A hushed throng of rags and bags, beards and caps, bare feet and flip-flops in every section. Some looked groomed and had neat suitcases – the newly homeless. Others were unwashed and wild-eyed with broken teeth and bandaged feet.

Since 2012, the number of homeless people in LA county has grown 75%, to 53,195 people. Spiraling rents, meagre wages, mental illness and drug addiction all play a role. Insufficient shelter means most sleep outdoors, vulnerable to the elements, abuse and assault.

The crisis has become normalised. Yoga instructors lead classes in parks dotted with supine figures in sleeping bags. An elderly man in a white hospital gown and slippers wanders down Spring Street, a block from City Hall, yelling, cursing, hooting. No one looks.

LA deserves credit for (belatedly) mustering a sense of urgency and funds - voters agreed to tax themselves $4.6bn to build housing. But authorities are struggling to turn that into progress.

I’m struggling to reconcile the city I love with the wretchedness. I did what I could, so I told myself. Wrote articles for a Guardian series, Outside in America. Tried to look homeless people in the eye, acknowledge their existence. Spent a morning chopping and peeling onions at a Skid Row shelter, vowed to go back, never did.

I did what most do: got on with life, enjoyed the weather, the food, the ocean, the concerts. I could pretend that it was hard, that I felt forever nagged by the extreme inequality. It wasn’t, and I didn’t. The great, terrible truth is that the wonders and distractions of Los Angeles made it easy, over the years, to look away. To no longer care quite so much.