Re-distilling Bug689189.pdf got 8000+ shadings from source 70 ones.
Passing to Ken since he handles pdfwrite from now.
*** Bug 689572 has been marked as a duplicate of this bug. ***
Seems that at present we have no way to know if use of a shading pattern is initial or reuse. Each pattern seems to get its own unique ID, which means we can't simply keep a cache and test IDs. Looks like we need to cache patterns and their matrix, also the shading dictionary associated with the pattern so that we can test new patterns to see if we already have a stored copy. Lots of work, prone to error.... However, there is nothing actually wrong with the current output except size and performance, so altering to 'enhancement'.
Enhancement still missing in Ghostscript 9.03
Commit fe99ca5fd2e3b191a76c7f7d791b72f3603e9fea fixes this. The output file now only contains 106 shadings, and is 41% smaller than before. Note that this fix also depends on the following commits: 90ec17f20be53db00fcbc2ada6931e7cc7b22b9e cdd142387a04a6d7ea519838e15204c4d7c681d8