I did a bit of research on this recently, and most if what I found was rule of thumb type stuff from the HVAC world. There, the recommendations are for as much as a full fan diameter's distance from a wall. For PC case design (especially SFF), that's pretty much a non-starter, and probably wholly unnecessary anyway. For a more usable rule of thumb, I've settled on approximately 0.25 * fan diameter, as this gives an equal area between the fan diameter area, and the area of the outer surface of an imaginary cylinder projecting from the fan to a wall. The idea being that the air has the same amount of space to flow through.
Needless to say, the actual performance is going to follow a curve, from no airflow at zero distance, to full airflow (equivalent to open air) at some distance (maybe the 1 * fan diameter mentioned). I haven't done those tests, but from what I've seen and read of people's experiments with the M1 and elsewhere, airflow definitely improves considerably from ~0.1 * fan diameter to ~0.2 * fan diameter (i.e, 10-12mm to 20-24mm clearance for a 120mm fan), so 0.25 * fan diameter would seem to strike a good balance between use of space and performance.