279 points · by nequo · 2y ago · 68 comments
So generally Wuffs is great and you should use it to decode your PNGs. There are some downsides: not all of the obscure bit depths and formats that PNG supports are loaded as-is, some are converted to more standard formats.
Also the Wuffs documentation is a bit hard to understand. It's a litle bit of a mission getting PNG decoding working. You can see my code for that here though: https://github.com/glaretechnologies/glare-core/blob/2c7174c...
Also, it has the funniest testimonials.
The biggest bottleneck in PNG decoding is zlib, which is not part of libpng. There are faster inflate implementations, but nowhere near 5x.
The second slowest thing is unfiltering, but it takes only 10-20% of the decoding time, so even lightspeed implementation would make little difference.
There is possibility of a 10x difference when encoding, but that's not due to libpng being slow, but because it's possible to apply worse compression and there are dedicated crappy-but-veryfast encoders.
Wuffs the Language - https://news.ycombinator.com/item?id=26731305 - April 2021 (75 comments)
Wuffs’ PNG image decoder - https://news.ycombinator.com/item?id=26714831 - April 2021 (138 comments)
For debugging i believe you can generate your own source maps and use gdb as a backend to talk with your custom debugger.
Today C makes most sense given the WUFFS language is still in flux.
[Edited to fix a serious typo]
> that can then be shipped like normal C, so you don't get the ecosystem friction like with ex. Rust.
Emitting Rust doesn’t help with this.
My understanding is that compiling unsafe C to WASM and back would also guarantee safety with respect to buffer overflows, integer arithmetic overflows and null pointer dereferences.
It’s nice not annotating code to explicitly prove invariants to the compiler like you would in say Wuffs or Rust, but I suppose that’s what limits performance.
What seems nice about wuffs is that it has no side effects and a clear project scope. Deserialization is so riddled with severe issues that it does kind of warrant its own DSL. OTOH, some legacy formats will probably never be ported.
But the tradeoff is that you need to rewrite your code for Wuffs, while WasmBoxC can sandbox anything that compiles to wasm and prevent it from corrupting the outside, including existing code in C, C++, Zig, unsafe Rust, etc. etc.
Not fatal, but perhaps annoying.
I would be glad to have a try but the language specification and documentation is almost non existent.
Note this does not prevent unscrupulous companies abusing dominant market positions to voluntarily embed machine and serial hash watermarks.
To be clear: formats like pdf, ps, webp, svg, and tiff are so badly implemented in some ecosystems... they can't _ever_ be assumed safe input formats. Thus, at some point people need to spin up an actual VM to transcode a "web" version, and scrub each stage of the rendering pipeline like a virus or header injection is already present.
"I never play where nice things are, and don't break things" (Eliza Mowry Blven, The Humanitarian Review, Volume 3, March, 1905)
Cheers =3
I've yet to find a better method than Honeypots to sustainably mitigate the complex leaky dependency mess on traditional architectures. It has been my experience that "all software is terrible, but some of it is useful".
It may just be my bias, but I see code smell getting worse in recent decades...
Have a nice day, =3
try to ever read any code for PDFs and see all the horrors.
Google gave up and just bought the code from foxit.
They just bought foxit code to save years of development when they wanted to ship PDF reader in Chrome.
Your comment about "the only viewer that is semi-correct" is also wildly off the mark.
Parsing correctly written PDF files is hard but multiple engines can do it correctly.
Parsing real life PDFs is much harder then correctly implementing PDF spec because lots of PDFs are just broken. They generators create invalid PDF files and then PDF readers have to spend heroic efforts to somehow make sense of this brokenness. Adobe does it better than most because... well it would be embarrassing if they didn't. They invented the format, they make money from their tools, they were doing it the longest, they have the largest archive of broken PDFs for testing etc. It's hard to expect that e.g. an open-source project with one or two developers can match that.
I work on SumatraPDF so I know.
edit: it seems Summatra doesn't support PDF forms? Either AcroForms or XFA forms?
I understand PDF has a bunch of limbs, but I always assumed the JS stuff was at least separate from the parsing. (I am familiar with the PDF format at a lower level but I never touched any of the weird features.)
I work a lot in OpenSCAD, and had a need to design some custom graph paper. So I found the subset of SVG which was similar to OpenSCAD. :)
[0]: https://github.com/WebAssembly/wabt/tree/44837a7236e85c048de...
[1]: https://github.com/WebAssembly/wabt/issues/2289#issuecomment...
Even if I told you some of the numbers I’ve seen in my experiments and usage, it wouldn’t be wise to trust them or let them taint your opinion.
Please, let the end brackets should be enough.