“Bridesmaids” is so funny, and has so many It’s about time! qualities to it, that you can easily overlook the fact that it’s too long and has too many dangling, underdeveloped threads. It’s miraculous that the movie exists at all, never mind whether its execution is flawless.

The film is a starring vehicle for “Saturday Night Live’s” current funniest female, Kristen Wiig, a gifted comic actress who can play smart, dumb, ugly, and pretty with equal dexterity. She wrote the screenplay with her old sketch-and-improv pal Annie Mumolo (who plays her seatmate in the soon-to-be-famous airplane scene), having been urged to do so by Judd Apatow, who liked what Wiig did with her brief screen time in “Knocked Up.” Apatow, known for running a schlubby boys’ club, wanted to produce something with a female ensemble. Whether Wiig and Mumolo’s sensibilities naturally meshed with his or whether he wielded some creative influence as the film’s producer, I don’t know, but “Bridesmaids” feels very much like something from the Apatow factory: vulgar, hilarious, sweet, and more than two hours long.

Raunchy R-rated comedies have been popular off and on for more than 30 years, but almost none of them have been led by women. We’ll save the discussion about why that is for another day; for now let’s just say it’s about time someone got serious about breaking that trend! Girls like jokes about sex and poop, too, apparently! And it’s about time someone made a female-driven movie that explored the way women’s friendships actually work. Or that addressed the subject of a friend’s impending marriage with real humor and truth. Or that centered on a woman who’s supposedly going through a rough patch of life whose life actually IS pretty screwed up, and yet who isn’t an object of complete ridicule, either.

In “Bridesmaids,” Wiig plays Annie, a thirtysomething Milwaukee woman whose boyfriend dumped her after her business failed. In most movies, a woman in this situation would still live in a huge apartment in Manhattan and wear designer clothes, and her unluckiness at love would be fixed once she let her hair down and quit wearing eyeglasses. Not Annie. Annie’s forced to share a small apartment with a grotesque Englishman (Matt Lucas) and his even more grotesque sister (Rebel Wilson), while working part-time at a jewelry store owned by a family friend. Barely able to pay her bills, she may have to move back in with her mom (the late Jill Clayburgh, in her final film role). As for romance, she has a “sex buddy” arrangement with a smug jerk named Ted (Jon Hamm), whose booty calls she dutifully answers no matter how late the hour.

Then Annie’s best friend since childhood, Lillian (Maya Rudolph), gets engaged, and Annie is appointed maid of honor. Though she’s genuinely happy for her friend, the timing could hardly be worse. Annie can’t afford all the expensive nonsense that goes into being a maid of honor, and she’s not in the mood to have mushy, giddy love rubbed in her face. Things become more vexing when she meets Helen (Rose Byrne), the super-rich wife of Lillian’s fiance’s boss and one of Lillian’s bridesmaids. This Helen person has really latched on to Lillian in the few months she’s known her, and now Annie feels vulnerable and threatened.

There are laughs to be mined in the contest of wills between Annie and Helen: Who can be the better friend to Lillian while passive-aggressively dissing the other?? But where many wedding comedies dissolve into complete cattiness, this one stays fairly grounded. Annie and Lillian have a true, deep love for one another, the way best friends do. Helen will ultimately not be able to come between them — and hey, guess what? She’s not even really trying to. Funny though it may be to paint the beautiful rich snob as a one-dimensional villain, “Bridesmaids” acknowledges that Helen has a point of view, too, and isn’t just a cartoon. Maybe I’m still reeling from last week’s “Something Borrowed,” where the two “best friends” did nothing but tell lies and undermine each other the whole time, but it’s refreshing to see a movie in which the female leads aren’t completely psychotic b-words. That shouldn’t be too much to ask, especially in a movie aimed at female audiences, and yet….

Anyway, Annie must also now contend with the other bridesmaids: Rita (Wendi McLendon-Covey), a frazzled and burnt-out housewife; Becca (Ellie Kemper), a naive newlywed; and Megan (Melissa McCarthy), the butch and rowdy sister of Lillian’s husband-to-be. Rita and Becca, at opposite ends of the “wife” spectrum, provide balance to the ensemble but don’t get much to do in the story. Megan, though — played with all-out insane gusto by the ridiculously funny Melissa McCarthy — proves highly valuable in getting Annie out of her funk.

As all of this is going on, Annie meets a new man, a kindly police officer named Rhodes (Chris O’Dowd). Annie isn’t focused on him, though, and neither is the movie. The movie is most interested in showing Annie’s progress from sad-sack to new-lease-on-life. It is there — not in her romance, not even in her friendship with Lillian, but in her own personal journey — that the movie finds its greatest emotional resonance.

Oh, but never mind emotional resonance. Is it funny? Good heavens, yes. Wiig and Mumolo, both performers at heart, wrote a screenplay that gives the actresses ample opportunity to create vivid, loopy characters, and to explore some outrageously fun situations. There’s a scene of bathroom humor that’s funnier than most scenes of bathroom humor — and yes, that’s at least partly because it involves a gender not usually associated with that sort of thing. Comedy comes from juxtaposition, and there’s greater contrast between a toilet and a beautiful woman than between a toilet and Seth Rogen. There’s also a sequence aboard an airplane that has all the women cutting loose in one way or another, always in ways that are true to their characters. The director is Paul Feig, who knows a thing or two about character-based comedy and the humor of humiliation: He created “Freaks and Geeks” and has directed episodes of “Arrested Development,” “The Office,” “Bored to Death,” “Parks and Recreation,” and “Nurse Jackie.”

But now let us mention the problems. The film feels much longer than it needs to be (the Apatow curse), and there are remnants of what I assume are deleted plot threads that don’t go anywhere. The stuff with Annie’s weird roommates doesn’t really work; they’re absurd characters in a movie that is otherwise grounded in reality, and their style is at odds with everything else. The connection between Annie’s mom and Alcoholics Anonymous keeps getting mentioned without any purpose or payoff. Annie’s tendency to take out her frustrations on the customers at the jewelry store is belabored, and suffers from comedy-sketch-itis. More discipline is called for — tighter editing, more consistent choices, a clearer overall vision of what the movie’s tone should be. Those are the things that often separate a good, funny comedy from a truly great one.

Like I said, though, it’s stunning that an R-rated female-driven comedy has been made at all, let alone that it’s often uproariously funny and centers on believable characters. I hope it leads to better things. Curious thing about “SNL.” The show is well-known for its funny women — and yet it has never launched any of those women to a huge movie career. There’s been no female equivalent, so far, of Eddie Murphy or Will Ferrell or Mike Myers. If “Bridesmaids” does it for Wiig … well, it’s about time.

B (2 hrs., 5 min.; R, a lot of harsh profanity, some gross-out humor, a lot of vulgar dialogue, some strong sexuality played for laughs.)