# How to deal with \`undefined\` buffers in ReleaseSafe mode

**URL:** <https://ziggit.dev/t/how-to-deal-with-undefined-buffers-in-releasesafe-mode/16738>\
**Category:** Help\
**Tags:** language\
**Created:** [July 16, 2026, 10:38am UTC](https://ziggit.dev/t/how-to-deal-with-undefined-buffers-in-releasesafe-mode/16738 "2026-07-16T10:38:11Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![lalinsky](https://ziggit.dev/user_avatar/ziggit.dev/lalinsky/32/3720_2.png) [@lalinsky](https://ziggit.dev/u/lalinsky)\
**Post date:** [July 16, 2026, 10:38am UTC](https://ziggit.dev/t/how-to-deal-with-undefined-buffers-in-releasesafe-mode/16738/1 "2026-07-16T10:38:12Z")

</div>

I’d really like to use ReleaseSafe builds by default, but I keep finding them unreasonably slow. A common source of slowdowns is `var large_buf: [N]u8 = undefined`. If you have something like that in the hot path, it has meaningful impact. I’ve seen some other thread that memset is not actually as far as it should be, so that’s one angle to tackle, but I’d possibly like to opt out of the memset. Is there a way to avoid this, while still keeping all the other runtime checks in the function?

---

<div class="post-metadata">

**Author:** ![Sietse2202](https://ziggit.dev/user_avatar/ziggit.dev/sietse2202/32/8385_2.png) [@Sietse2202](https://ziggit.dev/u/Sietse2202)\
**Post date:** [July 16, 2026, 10:46am UTC](https://ziggit.dev/t/how-to-deal-with-undefined-buffers-in-releasesafe-mode/16738/2 "2026-07-16T10:46:09Z")

</div>

Yeah it’s called [`@setRuntimeSafety`](https://ziglang.org/documentation/0.16.0/#setRuntimeSafety)

---

<div class="post-metadata">

**Author:** ![lalinsky](https://ziggit.dev/user_avatar/ziggit.dev/lalinsky/32/3720_2.png) [@lalinsky](https://ziggit.dev/u/lalinsky)\
**Post date:** [July 16, 2026, 10:53am UTC](https://ziggit.dev/t/how-to-deal-with-undefined-buffers-in-releasesafe-mode/16738/3 "2026-07-16T10:53:00Z")

</div>

I know about that, but I’m not sure how to use it in my case. I want the buffer initialization to not trigger the memset, but I want buffer usage to trigger bound checks. Can I turn it back on in the middle of a block? Maybe I should just try that.

---

<div class="post-metadata">

**Author:** ![pasta](https://ziggit.dev/user_avatar/ziggit.dev/pasta/32/6273_2.png) [@pasta](https://ziggit.dev/u/pasta)\
**Post date:** [July 16, 2026, 11:03am UTC](https://ziggit.dev/t/how-to-deal-with-undefined-buffers-in-releasesafe-mode/16738/4 "2026-07-16T11:03:58Z")

</div>

Out of curiosity how large `N` is causing you issues here, and how much of a performance impact does it have?

---

<div class="post-metadata">

**Author:** ![Sietse2202](https://ziggit.dev/user_avatar/ziggit.dev/sietse2202/32/8385_2.png) [@Sietse2202](https://ziggit.dev/u/Sietse2202)\
**Post date:** [July 16, 2026, 11:05am UTC](https://ziggit.dev/t/how-to-deal-with-undefined-buffers-in-releasesafe-mode/16738/5 "2026-07-16T11:05:08Z")

</div>

You can do this:

```zig
var buffer: [2048]u8 = blk: {
   @setRuntimeSafety(false);
   break :blk undefined;
};

...

```

---

<div class="post-metadata">

**Author:** ![lalinsky](https://ziggit.dev/user_avatar/ziggit.dev/lalinsky/32/3720_2.png) [@lalinsky](https://ziggit.dev/u/lalinsky)\
**Post date:** [July 16, 2026, 11:17am UTC](https://ziggit.dev/t/how-to-deal-with-undefined-buffers-in-releasesafe-mode/16738/6 "2026-07-16T11:17:23Z")

</div>

The last case I was investigating was 4KB buffer, but it was allocated on stack in a function that was called close to 100K times per second. Moving the buffer out of stack gained around 8% of my benchmark.

---

<div class="post-metadata">

**Author:** ![pasta](https://ziggit.dev/user_avatar/ziggit.dev/pasta/32/6273_2.png) [@pasta](https://ziggit.dev/u/pasta)\
**Post date:** [July 16, 2026, 12:21pm UTC](https://ziggit.dev/t/how-to-deal-with-undefined-buffers-in-releasesafe-mode/16738/7 "2026-07-16T12:21:21Z")

</div>

To be fair on this it may also be sensible to move the buffer up the stack a function or two. I appreciate that’s not always sensible, but it’s a somewhat idiomatic pattern for this kind of thing.

It’s so common though, 4KB is `MAX_PATH` a lot of the time. This feels like an interesting performance footgun others may hit.
