Rating: 4 stars

The best films teach you how to watch them within the first few minutes. “Blindspotting” is no exception. The film gets off to an exhilarating start, with split-screen images of Oakland, Calif., unspooling to the tune of a soaring aria. It’s a vibrant, contagiously joyful mosaic of street life, parties, Warriors and Raiders fandom and workaday grit. But soon a disparity sneaks in: A shot of an African American kid popping wheelies comes up alongside a white guy riding a bespoke penny-farthing bicycle. The corner store rubs right up against a Whole Foods.

A few moments later we see Collin, the hero of “Blindspotting” played by the Tony-winning “Hamilton” actor Daveed Diggs, being released to probation, impassive while he listens to the judge’s instructions. The film gets underway in earnest when Collin is three days away from having his probation lifted, as he sits in a car with his hotheaded best friend, Miles (Rafael Casal), and the car’s driver. What starts out as a Linklater-esque slice of guy-life turns into a comic routine worthy of the Marx Brothers, albeit with a decidedly foreboding subtext.

Here is what we’ve learned: “Blindspotting” will be a tale of Oakland, but it will be a tale of two cities; we will immediately be on the side of Collin, who although he’s a felon evinces a soft-spoken, gentle manner that is irresistible. And Miles — a tattooed white guy sporting a gold-toned grill, a mouth full of casual racial epithets and abiding resentment toward the gentrifiers colonizing his town — will be the most outlandish source of the film’s frequently uproarious humor. But he will also, most likely, be the source of Collin’s undoing.

Whether and how that precisely ensues over the next few days forms the structural spine of “Blindspotting,” directed by Carlos López Estrada from a script written by Diggs and Casal, both of them gifted and charismatic performers who grew up in the Bay Area and are lifelong friends. As the movie counts down the days until Collin will be released from his halfway house, we follow as he tries to keep on the straight and narrow, despite Miles’s worst anarchic impulses. When Collin witnesses the murder of an unarmed black man at the hands of a white police officer, he’s pulled into a vortex of grief, guilt and unresolved trauma. While self-preservation dictates keeping his head down, Collin’s nagging self-respect suggests otherwise.

As a parable of social mobility and selling out, “Blindspotting” shares thematic DNA with the recent comedy “Sorry to Bother You,” which is also, coincidentally, set in Oakland. But Diggs and Casal’s have more control of their material, and their scope is much bigger, as they take in the entirety of a community in which mostly white tech bros and artists are threatening to displace generations of deep-rooted, mostly African American working-class families. When Collin and Miles go to their moving job every day, they stop by the bodega on the corner, which now sells $10 green juice alongside $1 “loosies.” Miles hates it, but Collin isn’t so sure; he’s not reflexively opposed to change if it means better health and prospects. When Miles predicts that Collin will soon be wearing suspenders and riding a Vespa to Whole Foods, Collin murmurs apologetically that they do have good produce.

What start as teasing, playful barbs grow into more high-stakes tensions as the plot of “Blindspotting” takes form. For every amusing sequence skewering cultural appropriation, bourgeois posing and racial cluelessness, there are chilling moments of violence, or would-be violence. Punctuated by Diggs and Casal delivering improvised raps — their natural rapport bubbling to the surface with effervescent ease — the film often plays like a modern-day musical, with the same lilting, emotionally heightened energy. (A scene when Miles tries to unload a box of used curling irons at a beauty shop isn’t exactly necessary, but it’s utterly delightful.) The film’s title is inspired by Collin’s ex-girlfriend, Val (Janina Gavankar), who is studying psychology and uses the term as a way to remember Rubin’s Vase, a visual exercise in which the viewer either sees a vase or two faces in profile. Seeing both at once, she explains, is “hella hard.”

It’s difficult to fit this many ideas into a relatively brief, often lighthearted movie without resorting to some didacticism. Collin and Miles’s encounters with neighbors and clients occasionally feel too obviously like they’re Standing for Something, and the film’s harrowing climactic scene depends on one whopper of a coincidence. But for the most part, “Blindspotting” is a remarkably vivid, seamlessly flowing examination of modern life that is willing to take on not just capitalism, structural racism and contested social space, but the perverse, even murderous implications of masculinity at its most tough and toxic.

As it becomes painfully clear to Collin that Miles’s impulsivity will land him back in jail — or worse — the dynamics of their friendship come under scrutiny, but it goes both ways. Miles might be able to get away with more because he’s white, but in his view Collin is afforded immediate authenticity and credibility because he’s black. (This matters a lot, to which a frightening scene of mistaken identity at an upscale cocktail party attests.) Just as Oakland itself is a gloriously ambiguous melting pot, nothing is precisely black or white in “Blindspotting,” a spirited, thoughtful, thoroughly entertaining valentine to a city and its still-unfolding history, and a bracing reminder that two things can be true at the same time. Understanding that fact will always be hella hard.

R. At area theaters. Contains crude language throughout, some brutal violence, sexual references and drug use. 95 minutes.