Live data from Hacker News

Wuffs’ PNG image decoder

nigeltao.github.io

81–90 of 144 posts

Re: Wuffs’ PNG image decoder

#81
post #52

Surprisingly, Go's png decoder is half as slow as the default libpng :( https://nigeltao.github.io/blog/2021/fastest-safest-png-deco...

This isn't that surprising. In general Go is about half the speed of C to barring specifically optimized code or calling out to a faster library this would be expected.

Re: Wuffs’ PNG image decoder

#82
post #2

Interesting. First time I've head of Wuffs. As someone that still uses C, this in particular sounds neat: (from https://github.com/google/wuffs#goals-and-non-goals ) """ Wuffs' goal is to produce software libraries that are as safe as Go or Rust, roughly speaking, but as fast as C, and that can be used anywhere C libraries are used. [...] Wuffs the Library is available as transpiled C code. Other C/C++ projects can u…

Wuffs touts its lack of memory allocation as a safety feature [0]. Rust could add a `#![forbid(alloc)]` declaration and achieve the same effect. I think this would be a good idea. Wuffs types are not parameterized with lifetimes, so they may contain references only to items with static lifetime. This means that Wuffs cannot implement linked lists, hash tables, or other common data structures. To support those structu…

Go & Java don't do reference counting. They have a GC instead.

Re: Wuffs’ PNG image decoder

#83
post #64

Earlier quoted context omitted.

Wuffs touts its lack of memory allocation as a safety feature [0]. Rust could add a `#![forbid(alloc)]` declaration and achieve the same effect. I think this would be a good idea. Wuffs types are not parameterized with lifetimes, so they may contain references only to items with static lifetime. This means that Wuffs cannot implement linked lists, hash tables, or other common data structures. To support those structu…

Isn't that stupidly limiting?

Depends. AFAICT it’s designed to be embedded in a c project; in that context, it’s merely saying “the wuffs part does not allocate; do that in the c code”.

Re: Wuffs’ PNG image decoder

#84
> Wuffs is not a general purpose programming language. It is for writing libraries, not programs. The idea isn't to write your whole program in Wuffs, only the parts that are both performance-conscious and security-conscious.

Aren’t all apps (anything not one-off scripts) performance and security conscious? Being performance and security conscious seems like the rule, not the exception.

Re: Wuffs’ PNG image decoder

#85
post #23

I know there are information theory tradeoffs, but if you want to go really fast, use JPEG. Specifically, LibJpegTurbo. I have been playing around with this, and it is fast enough to encode a 1080p+ 8bpp framebuffer in under 5 milliseconds. This is fast enough for interactive applications. Most web browsers likely use something similar to this, so as long as you encode quickly on the server you can expect fast decode…

Interesting! Do you have an example of how such a thing could be used in an interactive language?

Re: Wuffs’ PNG image decoder

#86
post #64

Earlier quoted context omitted.

Isn't that stupidly limiting?

Depends. AFAICT it’s designed to be embedded in a c project; in that context, it’s merely saying “the wuffs part does not allocate; do that in the c code”.

Makes sense.

Re: Wuffs’ PNG image decoder

#87
post #85
post #23

I know there are information theory tradeoffs, but if you want to go really fast, use JPEG. Specifically, LibJpegTurbo. I have been playing around with this, and it is fast enough to encode a 1080p+ 8bpp framebuffer in under 5 milliseconds. This is fast enough for interactive applications. Most web browsers likely use something similar to this, so as long as you encode quickly on the server you can expect fast decode…

Interesting! Do you have an example of how such a thing could be used in an interactive language?

Think about extreme forms of server-side rendered applications where you need to keep the client device as simple, cheap and locked-down as possible.

All you need are 2 streams: 1 from client-to-server w/ all touch/keyboard events, and another from server-to-client with JPEG frames. One could easily build client devices using FPGAs or other integrated technologies with this sort of architecture.

The only caveats are latency & bandwidth requirements, but there are strategies for managing this, as well as problem domains where sufficient constraints exist on both counts (i.e. secure local networks).

Re: Wuffs’ PNG image decoder

#88
post #31

Are there any compiletime benchmarks? I would be interested how much their approach scales in terms of code size, since they use likely SMT solvers to guarantee having no arithmetic overflows (which is more than Rust guarantees). Ideally as comparison with compile times of Rust programs.

Wuffs does not use a SMT solver. https://github.com/google/wuffs/blob/main/doc/note/assertion... explains.

Re: Wuffs’ PNG image decoder

#90
post #73

Earlier quoted context omitted.

Wuffs touts its lack of memory allocation as a safety feature [0]. Rust could add a `#![forbid(alloc)]` declaration and achieve the same effect. I think this would be a good idea. Wuffs types are not parameterized with lifetimes, so they may contain references only to items with static lifetime. This means that Wuffs cannot implement linked lists, hash tables, or other common data structures. To support those structu…

> Rust could add a `#![forbid(alloc)]` declaration and achieve the same effect. Isn't that pretty much what `#![no_std]` is for? You can still use an allocator with no_std, but you have to explicitly import it. https://docs.rust-embedded.org/book/intro/no-std.html

It seeems like Wuffs is not really designed to support dynamic memory allocation at all, which is typical for usecases like oneshot parsers.
Post reply on HN