"Physically I had to work very hard, because he was very aggressive, and I could expect that. I came into the match knowing that he's going to take his chances."
Federer, the fourth seeded 2009 champion, needed more than three hours to record his fifth win in five meetings against Russian Dmitry Tursunov who twice needed treatment on a leg injury.
His 7-5 6-7 (7-9) 6-2 6-4 win also gave him a fourth round spot for the 12th time beating the previous record of 11 set by Guillermo Vilas.
Federer, the 17 time major winner, next faces Gulbis who reached the last 16 for the first time since 2008.
"It was tough to lose the second set but nice to win the match," said 32-year-old Federer, who is contesting his 58th straight Grand Slam.
"It was not a straightforward win. I knew Dmitry would try different things, take big cuts at the ball but I am pleased to have played solid."
Gulbis, the 18th seed, won a fractious third round clash against 35-year-old Czech Radek Stepanek 6-3 6-2 7-5 in the Court One bullring, firing 19 aces and 45 winners.
After the match, Gulbis caused a stir by claiming tennis is no place for female players.
"A woman needs to enjoy life a little bit more. Needs to think about family, needs to think about kids. What kids you can think about until age of 27 if you're playing professional tennis, you know," said the 25-year-old.
Gulbis, whose last fourth round appearance at a major came in 2008 when he made the quarter-finals in Paris, insists he already has a game plan to tackle Federer.
"You don't need to be scared to do certain things against him, because most of the people they go on the court and they lose already before it has started," said the 18th seed. "I can tell you that's not gonna be the case with me."
Milos Raonic became the first Canadian man in history to reach the last 16 at Roland Garros.
The 23-year-old number eight seed defeated France's 29th seed Gilles Simon 4-6 6-3 2-6 6-2 7-5 in a match which ended in the gloom at 9.30pm local time.
Raonic will face either Martin Klizan of Slovakia or Spain's Marcel Granollers for a place in the quarter-finals.
Granollers was ahead two sets to one when play was called off for the night.
American 10th seed John Isner made the last 16 for the first time with a 7-6 (15-13) 7-6 (7-3) 6-7 (5-7) 7-5 win over Spanish 17th seed Tommy Robredo on the back of 77 winners and 17 aces balanced out by 74 unforced errors.
Isner, who has now played eight tiebreaks in 11 sets so far, carved the only break on Friday in the 11th game of the fourth set.
Isner is the first American in the last 16 since Robby Ginepri in 2010 and with Jack Sock and Donald Young still to play, the US could have three men in the fourth round for the first time since 1995.
Isner next faces Czech sixth seed Tomas Berdych, a semi-finalist in 2010, who beat Spain's Roberto Bautista Agut 6-1 6-2 6-7 (4-7) 6-4.
-AAP