How are people confident enough to build in ReleaseFast/ReleaseSmall?

FWIW my 2 projects are game development and embedded development. For game development I want my game to be as fast as possible: so ReleaseFast. For my embedded development, I don’t have the memory or storage space to store binaries that have these safety checks: so ReleaseSmall.

What I do so I “can sleep at night” is testing: unittests, capture code coverage (MC/DC), fuzz tests and actually running the software and abusing it. Zig makes it easy to implement unittests and fuzz tests. I use gcov and lcov to visualize the data for MC/DC code coverage. Will I ever be 100% bug free? Probably not, but I keep refining my test suite and my methods of testing.

The bigger question is: what are you building that makes you feel uncomfortable turning off safety checks and letting the compiler fully optimize the code? For my game: I have my friend group playing it. I am using a new network stack with the old everything else (very old C++ code). My network stack is fully tested and they have yet find exploits/crashes. My embedded development project: I am running bare metal, custom bootloader, OS, secure boot implemented, …

When reading some of the concerns here, I really had to think back to the FillC talk: maybe adding something similar as a target would give people more peace?

2 Likes

If there is a sensible and useful check the compiler could insert automatically, its proper place is in the high level code, not the low level code. The idea that it’s the compiler’s job to go behind my back and secretly insert a ton of garbage into my software is exactly why I prefer Zig to anything else. What ever happened to “No hidden control flow”?

When you’re testing code, it’s fine to say “Screw it, I have no idea if my code is correct, throw whatever you got at the wall and see if anything sticks”. In code I put my name on, I absolutely do not concede that literally every part of it could be busted.

I also would agree with @matklad that better primitives like slices in Zig make it easier to write correct software.

E.g. Java had a vulnerability a few days ago in an AVX-512 base64 decoder. Basically they had an integer underflow that could turn into a buffer overrun. The usual issue.

I wrote this Zig implementation of the same thing:

Of course, my decoder is a bit more strict because I only accept an input string that’s a multiple of 4 bytes, but that technique is available to all, including Java. It’s easy to prove for all arithmetic I use that it can’t underflow. (Yes, I did a weird thing with the interface, leave that aside if you can.)

I’m not doing anything serious, just fun hobby stuff. I’ve seen people talk about building in ReleaseSmall/Fast casually and without elaborating on the effort they are putting in to have confidence in their software, so i figured I’d ask.
It’s been encouraging to hear folks more explicitly talk about what they are doing to gain confidence that their software is correct!

2 Likes