In the hands of Judd Apatow, romantic comedies become epics. “The 40-Year-Old Virgin,” his feature-film debut, was a comparatively scant 116 minutes; “Knocked Up” ran 129 minutes and “Funny People” an obscene 146 – durations that far exceed genre protocol. In his first two pictures, which remain his best, the protracted running times felt like a welcome breath of improvised air, lengthy for the same reasons John Cassavetes’ films were lengthy: They allowed more time for his characters to simply live, rather than further the plot with every minute action.

But in “Funny People” and now “This is 40,” his least inspired films to date, the generous lengths (“This is 40” clocks in at 134 minutes) ramble toward unwieldy detours with insignificant characters, not building wit and nuanced character development in everyday situations so much as padding stories that could have benefited from a judicious editor. It’s hard to imagine what will be included in the DVD deleted scenes from “This is 40.” Surely, everything that was shot must have been stuffed into the final product; this can be the only justification for the film’s almost catastrophic second half.

The core of the movie, which opens in theaters today, is a very good one. It’s a spin-off of sorts featuring Pete and Debbie (Paul Rudd and Leslie Mann), who had an engaging subplot in “Knocked Up.” This time, the movie belongs entirely to them, as they try to keep their family together on the precipice of the 40th birthdays. Pete still runs a record label specializing in retro rock and alternative acts and willfully ignoring modern music’s popular whims. With the state of the music industry in dire straits, he’s barely scraping by. His sole client, it seems, is Graham Parker, a good sport who plays himself as a gout-suffering dinosaur attempting to launch a comeback for a diminishing cult of die-hard fans (Billie Joe Armstrong and Ryan Adams appear later in pleasing cameos).

Debbie runs her own business, a chic clothing shop, but she’s having financial problems too: She suspects that one her employees has stolen thousands of dollars from the store. Add to these struggles two children, one of whom is a teenage girl carrying teenage-girl baggage, a third child potentially on the way, and the perpetual problem of Pete’s mooching, guilt-tripping father – a lumpy Albert Brooks, brilliant as always – and it all adds up to a perfect middle-aged storm of stress. This, in turns, leads to decreased passions, increased fights, and a reliance on the unhealthy creature comforts – cupcakes for Pete and smoking for Debbie – that both were trying to quit.

Apatow can be an astute surveyor of relationship discord, diagnosing relatable problems with uncomfortable accuracy. And he’s such a great director of actors that Rudd and Mann are always in sync as performers, even when their characters’ relationship seems hopelessly scrambled.

But when “This is 40” careens off the rails, it never returns. The plausible humor, both surprising and familiar, that complemented the dramatic elements so well in the first half, eventually acquiesces into the mean-spirited personal attacks of shock-jockery, with jokes buried so deeply under piles of contempt and cynicism that they are all but nonexistent. There’s a particularly cruel series of scenes in which violence is directed at schoolchildren and their parents – inside a school – that feels offensively mistimed in the wake of Sandy Hook.

From then on, we get an underdeveloped subplot about Debbie’s long-absent biological father returning to her life (John Lithgow), that deserves either much more screen time or none at all, but not the scant and awkward treatment it receives here. And speaking of scant, we get plenty of half-naked shots of Megan Fox, who plays one of Deb’s employees – changing clothes in her shop, swimming in a pool, speaking words with orgasmic salaciousness to Jason Segal, who appears as an arrogant personal trainer. I like to look at Megan Fox as much as the next straight male, but her continued presence in “This is 40” is superfluous, the result of a director thinking less with his brain than with another part of his anatomy. But judging by the way the film’s tenor shifts so wantonly from probing domestic dramedy to a mean, phony and distracted mess, thought left this bar long before last call.