After 17,216 performances, 6.5 million visitors, and who-knows-how-many gargantuan hats, San Francisco’s enduring “Beach Blanket Babylon” is ending its run.

The zany spoof show, which has been running since 1974 and claims to be the longest-running musical revue in the world, will play its final performances on New Year’s Eve, the producer announced on Wednesday.

“I just felt it was time — after 45 years, it was the right time to close,” said the producer, Jo Schuman Silver. “It’s better for us to go out on top than to drag this out.”

The pun-and-sight-gag-filled show has a feather-thin plot — Snow White, looking for love, wanders the world encountering famous people who sing pop song parodies, often about politics and celebrity. It has become a treasured San Francisco staple, renowned as much for its spectacularly sculptural headgear as its content. (A San Francisco skyline hat is 14 feet high, nine feet wide and weighs more than 250 pounds.) It has been performed for a parade of notables, from Liza Minnelli to Queen Elizabeth II.