It was a foregone conclusion for the last few seasons. As long as Ray Allen remained healthy and productive – doing what he has been doing since he came into the NBA in 1996 – he was going to overtake Reggie Miller as the NBA’s most prolific three-point shooter at some point. The only unknown was the time and place.

It happened Thursday night in Boston. The Celtics lost to the Lakers, which in the big scheme of things may be more critical. And Allen knocked down three three-pointers to pass Miller, who was in the building doing commentary for TNT.

The two chatted before the game and then hugged after Allen’s first-quarter three-pointer enabled him to set the new record. Miller then told his television audience what everyone who has been following Allen already knew: the new record holder takes care of himself with the dedication of a Welsh nanny.

“At the age of 35, to still be considered the best shooter in the league, shows how much he has kept in shape over the years,’’ Miller said.

Allen really broke the record a long time ago, when he dedicated almost every aspect of his day-to-day life to being the best basketball player he could be. That meant a lot more than hoisting shot after shot in empty gymnasiums. It meant watching what he ate and drank to the point where, at the age of 35, he is a living, breathing advertisement for self-preservation.

“I’ve always compared my body to a Ferrari,’’ he said. “So I always try to put the best gas in it. Eating the right food has always been important.”

He could not possibly have passed Miller without such dedication and, needless to say, without the benefit of good luck from the Injury God. He sees one as directly related to the other. You take care of yourself with Prussian efficiency and discipline, you’re not going spending time nursing an ailment.

“I know that whatever I chose to do,’’ Allen said, “that I would have been great at it because of my ability to commit to what I do.”

This is Allen’s 15th season in the NBA and, among the Class of 1996, he is one of the few still playing regularly and producing. (Kobe Bryant also falls into that category. Marcus Camby, sort of the anti-Ray Allen, is, once again, hurt.) He didn’t miss a game in his first six seasons. He has missed big chunks of time in only two of the those 15 seasons, his first and last in Seattle, due to ankle/foot surgeries.

He believes he’s still around and productive because of his slavish devotion to a routine, whether it’s shaving his head before every game to making sure he has the same parking spot every day. And, he never hesitates to add, he watches what he eats and drinks and makes sure he gets his proper rest.

“He is dedicated about that part of his life,’’ his father-in-law, John Williams, said of Allen. “He doesn’t smoke. He doesn’t drink. He doesn’t even drink coffee.”

The NBA, Allen believes, is a six-month edition of ‘Groundhog Day.’ It doesn’t matter if he’s in Portland or Atlanta, it’s the same. He always has baked chicken thighs, steamed rice and a green vegetable before every game. “Now, it’s broccoli,’’ said his wife, Shannon. “But we also do asparagus.” He will occasionally sample a piece of steak after a game. The next time your read about him clubbing will be the first time.

“You can’t be in two different places at one time, you can’t try to do too much, and be social and live this glamorous life,’’ he said. “If you want to be great, you have to commit and devote yourself to this job, (to) getting the rest at nighttime, and eating right, and avoiding the temptations on the road or whatever.  This is a 365-day-a-year job. But when you commit to it, it pays you back.”

Allen’s devotion to his own well-being is paying almost unimaginable dividends for him and the Celtics. He is shooting a career best percentage from the field and from three-point territory. He leads the Celtics in overall minutes played. He has not missed a game. For the first time as a member of the Celtics, he was named to the Eastern Conference team for the All-Star Game by the coaches. His previous two trips to the game were as commissioner selections.

He said after his record-setting performance that he feels as good as he ever has, that he could “go forever.” He is under contract through next season, but his Celtics’ teammate, Paul Pierce, thinks Allen could go for another four or five years.

This doesn’t happen to guards. They tend to go in their mid-30s. But what we’ve seen this year out of Allen is a testament to the hard work he has put in over the years and to his obsessive fidelity to diet, rest and consistency.