This is a followup to Difference in compilation time between two slightly different versions.
As became obvious when asking that question, the speed of that compilation is seriously affected by the length of the comma separated list
\ReferencedID. This is the list of the labels collected from the text. But this list may contain duplicates, and in fact in the example in my question, it does. So, how can one delete duplicates from a comma-separated list?
For concreteness, the list is my example is: