I know that amsmath typesets at least twice its material, the first one for measurement and that it takes measures (sic) to avoid some counters being updated twice.
Is there a switch a macro writer could use to inform LaTeX not to update counters (which are global in LaTeX) when it is needed to typeset some unknown contents #1 inside a box, which will be discarded later?
update from info gathered from egreg's answer and a (belated) look in the sources. It is not as I said above that amsmath avoids for some counters to be updated; it avoids it for all, because it uses a list of all counter names which is kept up-to-date by the latex kernel, and designed to allow anyone using it to do things with all these names. The conclusion is thus that amsmath defines the macro pair \savecounters@/\restorecounters@ because it needs the functionality, but that anyone can copy their definitions (\savecounters@ defines what \restorecounters@ will do) and use them with the same effect without having to load amsmath or even any portion of it. Just replace \@nx by \noexpand.

\ifmeasuring@is true in the first step and false during actual typesetting. However subtle problems can arise, if the counter's value changes from one to two digits. Can you give an example? – egreg Sep 27 '13 at 20:12amsmathfor background, I am asking for a switch provided by the LaTeX kernel. I have not looked at what exactlyamsmathdoes to avoid counters being updated twice, I am asking if LaTeX provides now a way to do that. – Sep 27 '13 at 20:18