dfrg / zeno

High performance, low level 2D path rasterization library in pure Rust.
Apache License 2.0
101 stars 9 forks source link

Remove unsound casting of undefined data to defined data #7

Closed notgull closed 7 months ago

notgull commented 9 months ago

In the rasterizer, arrays of data are gradually initialized by creating an uninitialized array and writing into those arrays. However, this is technically unsound in Rust, and causes MIRI to fail when I try to run on it.

Out of curiousity, I tried switching it to zeroing the array first before writing to it. However, by some benchmarks I wrote it seems to have no effect on the speed of the system. So I think it's a viable solution to reduce undefined behavior.

notgull commented 7 months ago

@dfrg When you have a chance can you take a look at this?

dfrg commented 7 months ago

Yes, thanks. This looks good. The benchmark doesn't touch the modified AdaptiveStorage since it uses Scratch but I'm less concerned about that than the temporary arc storage for curves and if we're not seeing regressions there then I'm happy to remove the unsafe and address potential performance issues with the adaptive storage later.