Live data from Hacker News

Wuffs’ PNG image decoder

nigeltao.github.io

111–120 of 144 posts

Re: Wuffs’ PNG image decoder

#111

> Also, unlike Go or Rust, Wuffs’ memory safety is enforced at compile time, not by inserting runtime checks that e.g. the i in a[i] is within bounds or that (x + y) doesn’t overflow a u32. Am I missing something, or is this statement simply wrong? Have not used Go, but Rust checks its stuff at compile time as far as I know.

How would Rust check at compile-time whether an array index read from a file on disk (at runtime) is out of bounds?

Re: Wuffs’ PNG image decoder

#112
post #24
post #7

My favorite part of the Wuffs github page has to be the definition it gives for Dependent Types > ...Dependent types are a way to implement compile-time bounds checking, but they're not the only way, and there's more to programming languages than their type systems. Wuffs does not use dependent types. Wuffs looks really interesting! I don't think I've ever even heard of a language that is designed to only be used in…

There is T0, part of BearSSL. This presentation has an explanation of it (starts slide 19): https://t1lang.github.io/NorthSec-20190516.pdf

Ah - forgot about this. Thx for posting this. These little languages really keep the system footprint tiny compared to OpenSSL.

Re: Wuffs’ PNG image decoder

#113

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…

That is true, but on the other hand, Wuffles allows safe unchecked array indexing, which is a very hard problem that Rust doesn't attempt to tackle--in part because it spends most of its complexity budget on the borrow checker! I for one would be extremely interested in using Wuffles in the inner loop of many routines I currently write in Rust which are performance critical, and for which I know bounds checking is hu…

> I would particularly love it as an embedded language, rather than one needing a full-blown application.

Given the existence of [0], I imagine this is doable.

[0]: https://docs.rs/inline-python/0.6.0/inline_python/

Re: Wuffs’ PNG image decoder

#116

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…

That is true, but on the other hand, Wuffles allows safe unchecked array indexing, which is a very hard problem that Rust doesn't attempt to tackle--in part because it spends most of its complexity budget on the borrow checker! I for one would be extremely interested in using Wuffles in the inner loop of many routines I currently write in Rust which are performance critical, and for which I know bounds checking is hu…

Generational indices allow safe unchecked array indexing in Rust.

There are many papers that cover how to do this, starting with Alexis Beissegners thesis, up to the latest Rust belt project paper on GhostCell.

There are also many libraries implementing this, so that you don't have to do it yourself.

In practice, however, like the Wuffs project says, most code doesn't care about this. You only need this for very specific types of code, but if you need it, you have it in Rust.

---

On the other hand, I've asked above what happens if you try to open a png that doesn't fit in RAM, like one of those huge space photos that are >1 Tb in size.

Firefox just handles these fine, rendering only the part of the picture that you are looking at, using level of detail, etc.

This Wuff example assumes that you have enough RAM to decode the whole image at once, which is something that widely-used libraries are not allowed to assume, because they must support from embedded systems with little RAM up to absurdly huge images of our universe.

Re: Wuffs’ PNG image decoder

#117
post #57
post #7

My favorite part of the Wuffs github page has to be the definition it gives for Dependent Types > ...Dependent types are a way to implement compile-time bounds checking, but they're not the only way, and there's more to programming languages than their type systems. Wuffs does not use dependent types. Wuffs looks really interesting! I don't think I've ever even heard of a language that is designed to only be used in…

Wasm does at runtime what Wuffs does at the compile time for a typical slowdown of 2-3 times. As with Wuffs there is no allocation in the basic Wasm, the program works on pre-allocated buffers.

You can grow wasm memory while running a wasm module, can't you?

Re: Wuffs’ PNG image decoder

#118
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…

Goals and Non-Goals explain that wuffs is not a general purpose programming language. If all the allocations are done by code invoking the function implemented in wuffs there is no point analyzing lifetimes. For the intended usecase lifetime of the objects and their lifetimes fall into following categories:

* input buffer -> prepared by caller, must live as long as you are decoding it

* output buffer -> prepared by caller, must live as long decoder outputs to it

* fixed size decoder state -> allocated during initialization

* decoder state with size depending on input -> various compression formats formats typically include information about expected sizes, used dictionary sizes and similar so that required memory for it can be allocated ahead of time. You don't want memory allocations during the hot loop anyway. And if it turns out that content doesn't match sizes from header it's an invalid file.

Re: Wuffs’ PNG image decoder

#119
post #58

Earlier quoted context omitted.

The title changed multiple times. I've seen at least 3 in the last 30 minutes (safest, fastest and now this one).

why? usually I only see this happen for misleading headlines and appending "(year)" to old articles that might be construed as recent. what's misleading about the actual article's headline? as far as I can tell it seems to be true.

The author of Mango posted a benchmark on Reddit: https://www.reddit.com/r/programming/comments/mld1ob/the_fas...

                  load         save             
  ----------------------------------------------
  // image: 1165 x 859 (1943 KB) 24bpp
  libpng:       19.2 ms     494.7 ms 
  wuffs:        14.9 ms       0.0 ms 
  mango:        10.0 ms      84.7 ms 

  // image: 312 x 442 (43 KB) 32bpp
  libpng:        2.9 ms      18.3 ms 
  wuffs:         0.4 ms       0.0 ms 
  mango:         0.1 ms       7.3 ms 

  // image: 160 x 120 (13 KB) 8bpp
  libpng:        0.7 ms       9.5 ms 
  wuffs:         0.1 ms       0.0 ms 
  mango:         0.1 ms       3.2 ms 

  // image: 90 x 112 (23 KB) 24bpp
  libpng:        0.9 ms       3.9 ms 
  wuffs:         0.5 ms       0.0 ms 
  mango:         0.2 ms       1.3 ms

Re: Wuffs’ PNG image decoder

#120
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?

Yes.

I'm not so sure about the usefulness for an image decoder.

But if you are designing safety critical realtime software for controlling a car, then you kind of want the extra reliability guarantees that avoiding the heap gives you.

Post reply on HN