Harry Kane opened the scoring for the visitors before Konrad Laimer, Kingsley Coman and Joshua Kimmich scored before the hour mark to put the game to bed.
Bayern are now just two wins away from reclaiming the Bundesliga trophy with four games of the campaign still remaining after defending champions Bayer Leverkusen could only draw 1-1 at St Pauli.
What also impressed Kompany is that his team moved on quickly after being knocked out of the Champions League at the quarterfinals stage by Italian side Inter Milan in midweek.
"I know that everyone will say that it's normal for Bayern to win here," said Kompany before praising his team.
"But if you watch Heidenheim's last few games, especially the one against Leverkusen here, it wasn't easy for their opponents.
"It was a complete performance by the boys after a difficult week. Compliments to them."
Bayern can move another step closer to league title when they host Mainz on Saturday.