3 ms·
Well, one thing that does work for decoding regular old PNGs is separating the entropy decoding (in PNG, DEFLATE) from the prediction (what PNG calls filtering)
by pcwalton 5y ago
Well, one thing that does work for decoding regular old PNGs is separating the entropy decoding (in PNG, DEFLATE) from the prediction (what PNG calls filtering). You can create a pipeline where one thread is working on the entropy coding and handing off completed rows to a thread that performs the prediction decode. This doesn't get a 2x speedup because usually DEFLATE is slower than the prediction step, so it ends up bottlenecked on zlib, but it helps a good bit. (I implemented this in Rust at one point with the intention to ship in Firefox, but it never did.)
Of course, this only scales to 2 CPUs. Beyond that you will need to do some sort of splitting of the input to achieve wins (since no matter how much you optimize the filtering, you're still bottlenecked on DEFLATE, which is inherently serial).
- pornel 5y agoI assume iOS may have a problem of the application doing: for each path { decode(path) } and the OS can't parallelize that, because it learns about a new file only after decoding the previous one.
- geocar 5y agoHow I read nyanpasu64; I think that the point was that a web page will often have multiple png files -- often more than you have cores, so the gains of decoding a single specially-formatted png might disappear in practice. iDOT seems like overengineering to me: Why not break up the PNG and tile them in an SVG? This should be just as fast, about the same size, and you'd never have run the risk of inventing your own format and implementing it badly[1]. Users would probably be happier with all their SVGs being faster than having specially-crafted PNGs accelerated (if given the choice) [1]: https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2016-1811 https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2016-1811
- patrec 5y agoAmen!
- marcellus23 5y agoI’m a bit confused, are you suggesting they convert the PNGs into an SVG? How is that possible?
- geocar 5y agoI'm not entirely sure how to begin to answer this question. Forgive me if I start too early. An SVG is a list of compositing instructions for some (graphical) artefact. These instructions are given so that their dependencies (the things that must be composed before other things) are stated directly. If you have familiar with Adobe's Photoshop, you might imagine a SVG as a set of nested layers: An SVG "renderer" will simply compose these layers together in order to have some pixels to display. Now, to give a clear example of what I'm referring to, I am going to show you a simplified SVG that composes four png files together in tiles: <svg width="100" height="100"> <image x="0" y="0" width="50" height="50" href="data:image/png,xxx" /> <image x="50" y="0" width="50" height="50" href="data:image/png,xxx" /> <image x="0" y="50" width="50" height="50" href="data:image/png,xxx" /> <image x="50" y="50" width="50" height="50" href="data:image/png,xxx" /> </svg> That data:image/png,xxx stanza is the SVG-encoding of a PNG (a slight simplification: the format actually belongs to a number of different standards, that the SVG specification leverages). That is to say, I'm not exactly suggesting converting a PNG to an SVG: I am also suggesting breaking apart the (large!) PNG into several component PNG files (tiles) so that they can be decoded independently. Note carefully my example, how none of the tiles overlap. A decoder can (trivially) determine these instructions are independent, and so process them independently. Being able to decode parts of the resulting image independently is what the iDOT metadata makes possible: It is essentially a different encoding of the x/y/width/height information in the above, the difference is that SVG already existed.