A new coat of paint, especially one with any sheen, catches the light and shows every dent, nail pop, and rough patch on a wall. The time to deal with them is before painting, when the fix is simple.
Start with the obvious damage: holes from doorknobs and anchors, cracks at corners and seams, and any section that has been wet. Water-stained drywall should be checked for softness and replaced if it has lost its strength, once the leak itself has been fixed.
Then look at the wall in low, angled light. Nail pops, ridges from old tape, and patches that were never sanded flush all show up this way. Each one is filled or skimmed, then sanded until you cannot feel it with your hand.
Finally, prime every repair. Joint compound absorbs paint differently from the wall around it, and an unprimed patch will show through as a dull spot. With repairs primed, the finish coat goes on evenly and the wall reads as one surface.