In “Once Upon a Time … in Hollywood,” the new ’60s Los Angeles pastiche from Quentin Tarantino, Leonardo DiCaprio plays an actor whose stardom is in steady decline. This weekend demonstrated just how different DiCaprio’s career is from his character’s.

“Once Upon a Time … in Hollywood” sold about $40.4 million in tickets at theaters in the United States and Canada from Thursday night to Sunday. That’s a win for both Sony, the film’s distributor, and Tarantino, its director; it rivals “Inglourious Basterds” in 2009 for his best opening weekend ever. (Adjusted for inflation, the $38.1 million total for “Inglourious Basterds” comes out slightly ahead.)

Having two of the biggest names in Hollywood lead the new movie probably helped. The story centers on the professional relationship and friendship between a made-up TV actor, Rick Dalton (DiCaprio), and his longtime stunt double, Cliff Booth (Brad Pitt). Its splintered story mixes fact and fiction, and attempts to capture the energy of an era that saw Hollywood and hippie culture collide. The movie also features portrayals of many real-life figures, most notably the actress Sharon Tate, who is played by Margot Robbie.

“Once Upon a Time … in Hollywood” received generally strong reviews from critics — it currently holds an 86 percent fresh rating on Rotten Tomatoes. In his review for The New York Times, A.O. Scott wrote that the film “will stand as a source of debate — and delight — for as long as we care about movies .”