4 ms·
Regarding the lengths must match: > (i.e. you will get a panic in safe release modes) Should I take that to mean there is an unsafe release mode without the b
by titzer 4y ago
Regarding the lengths must match:
> (i.e. you will get a panic in safe release modes)
Should I take that to mean there is an unsafe release mode without the bounds check? But UB is mentioned too. Is there UB!?
It's 2023; I think we can afford a single branch to avoid UB, even in release mode.
- conradev 4y agoit is one of the build modes: https://ziglang.org/documentation/master/#Build-Mode https://ziglang.org/documentation/master/#Build-Mode
- titzer 4y agoInteresting, thanks for the link. I think that disabling safety checks is a thing you should only do if you are studying the cost of safety checks (i.e. a compiler switch only available to compiler engineers). IMHO, the whole point of safety checks is to find the bugs that are in your program[1]. Crashing it safely with an exact source stack trace is the nice way of both motivating you to fix it and also helping you fix it. [1] And there are bugs in your program. Right now. Bugs. In. Your. Program. Running without safety checks is like closing your eyes and rolling the dice.
- quic5 4y agoThere's also the compromise of only disabling safety checks per block e.g. in your hot loop with `@setRuntimeSafety`[1] where you are confident that they aren't needed. [1] https://ziglang.org/documentation/0.10.1/#setRuntimeSafety https://ziglang.org/documentation/0.10.1/#setRuntimeSafety
- laserbeam 4y agoMost software should probably release with safety checks on. Certain software shouldn't (i.e. games). Toolchains like zig give you that option and respect that you can decide what's most appropriate for whatever you ship. Arguing that safety checks should always be enabled doesn't really make sense. Context matters.
- kristoff_it 4y ago> Should I take that to mean there is an unsafe release mode without the bounds check? Yes, it's called ReleaseFast. > It's 2023; I think we can afford a single branch to avoid UB, even in release mode. Zig has 3 release modes: ReleaseSafe, ReleaseFast, ReleaseSmall. If you want the safety checks, just use the first. It might even be $currentYear, but many of the latest AAA games still don't always run at more than 60fps on my fairly powerful machine and I sincerely hope they were built with all the optimizations enabled.
- Maken 4y agoThat's probably because of the DRM.
- AnIdiotOnTheNet 4y agoAnd 60fps is the low end in an era where many monitors are 120-240hz. 4ms/frame is a pretty tight budget.
- titzer 4y ago> I sincerely hope they were built with all the optimizations enabled. Sure, but I don't agree that disabling safety checks is an "optimization". It is a regression in functionality that is betting on nothing going wrong. Bounds checks do not cost much[1]. Maybe if a bounds check disables vectorization[2]. [1] https://blog.readyset.io/bounds-checks/ https://blog.readyset.io/bounds-checks/ [2] https://github.com/matklad/bounds-check-cost https://github.com/matklad/bounds-check-cost There are a lot of techniques to remove bounds checks, e.g. in counted loops [3][4]. [3] https://ieeexplore.ieee.org/document/5381765 https://ieeexplore.ieee.org/document/5381765 [4] https://en.wikipedia.org/wiki/Bounds-checking_elimination https://en.wikipedia.org/wiki/Bounds-checking_elimination
- AnIdiotOnTheNet 4y agoIf that's what you believe, you are free to enable them as the programmer. Programmers who disagree are likewise free not to. This can even be decided on a scope-by-scope basis if so desired.