# Function inlining questions

**URL:** <https://ziggit.dev/t/function-inlining-questions/18529>\
**Category:** Help\
**Tags:** language\
**Created:** [November 20, 2026, 9:51am UTC](https://ziggit.dev/t/function-inlining-questions/18529 "2026-11-20T09:51:33Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![devengel](https://ziggit.dev/letter_avatar_proxy/v4/letter/d/e36b37/32.png) [@devengel](https://ziggit.dev/u/devengel)\
**Post date:** [November 20, 2026, 9:51am UTC](https://ziggit.dev/t/function-inlining-questions/18529/1 "2026-11-20T09:51:33Z")

</div>

this is not a question about the inline keyword.

does the compiler inline functions if it deems that they are simple enough, regardless of build releases, or it it exclusively tied to build release optimizations?

consider the following snippet from my project, would any of `new(), air(), blockData()` get inlined in debug mode? if so, why?

```zig
pub const Block = bitpack struct(u32) {
    id: u14,

    reserved: u18 = 0,
    pub fn new(id: u14) Block {
        return Block{
            .id = id,
        };
    }
    pub fn air() Block {
        return comptime Block{ .id = 0 };
    }
    pub fn blockData(s: Block) BlockData {
        return BlockRegistry.blockData(s.id);
    }
};

```

---

<div class="post-metadata">

**Author:** ![pzittlau](https://ziggit.dev/letter_avatar_proxy/v4/letter/p/ecae2f/32.png) [@pzittlau](https://ziggit.dev/u/pzittlau)\
**Post date:** [November 20, 2026, 10:29am UTC](https://ziggit.dev/t/function-inlining-questions/18529/2 "2026-11-20T10:29:52Z")

</div>

> [@devengel](#):
>
> Does function inlining happens regardless of build releases, or it it exclusively tied to build release optimizations?

It happens regardless of build mode. Inlining functions in Zig has specific semantics, that differ from what you may know from other languages. You can read more [here](https://ziglang.org/documentation/master/#inline-fn).

> [@devengel](#):
>
> consider the following snippet from my project, would any of `new(), air(), blockData()` get inlined in debug mode?

As far as I know they wouldn’t.

* * *

I would advise you to don’t use `inline`, if you aren’t very sure that you need it. Measure before you do it for performance reasons. And if you need it for `comptime` stuff you’ll find that out when you need it.

---

<div class="post-metadata">

**Author:** ![devengel](https://ziggit.dev/letter_avatar_proxy/v4/letter/d/e36b37/32.png) [@devengel](https://ziggit.dev/u/devengel)\
**Post date:** [November 20, 2026, 11:20am UTC](https://ziggit.dev/t/function-inlining-questions/18529/3 "2026-11-20T11:20:29Z")

</div>

Sorry, i didn’t make myself clear, i didn’t mean the inline keyword, i meant simply meant that function would get inlined by itself if the compiler recognizes that its a small enough function like the ones i showed above.

ill update my post.

---

<div class="post-metadata">

**Author:** ![pzittlau](https://ziggit.dev/letter_avatar_proxy/v4/letter/p/ecae2f/32.png) [@pzittlau](https://ziggit.dev/u/pzittlau)\
**Post date:** [November 20, 2026, 11:41am UTC](https://ziggit.dev/t/function-inlining-questions/18529/4 "2026-11-20T11:41:50Z")

</div>

Ah, no problem.

In that case, no, automatic inlining only happens in release modes. In debug none of them will get inlined automatically.

AFAIK, for the self-hosted backends there aren’t any optimizations like that in debug. And when building with the LLVM backend, Zig uses LLVM’s `O0`, which doesn’t run the regular cost-based inliner at all. The only inliner that runs at `O0` is `AlwaysInlinerPass`, and normal Zig functions don’t get LLVM’s `alwaysinline` attribute.

* * *

A small side-note on `air`. The `return comptime Block{ .id = 0 };` only forces the struct literal inside the function to be evaluated at comptime, it doesn’t inline or comptime-evaluate calls to `Block.air()`. If you want to avoid a function call for that even in Debug, you could just make it a constant instead: `pub const air: Block = .{ .id = 0 };`.

---

<div class="post-metadata">

**Author:** ![tholmes](https://ziggit.dev/user_avatar/ziggit.dev/tholmes/32/5641_2.png) [@tholmes](https://ziggit.dev/u/tholmes)\
**Post date:** [November 20, 2026, 11:42am UTC](https://ziggit.dev/t/function-inlining-questions/18529/5 "2026-11-20T11:42:47Z")

</div>

I think it’s mainly based on how often the function is called  
If it’s only called once it’s a no brainer to inline it  
If it’s called a thousand times, inlining it would be better performance but could make the binary size balloon, making it a poor choice  
If there are a lot of complex branches leading to scenarios where it could be called, inlining it would be a very bad idea cuz it could lead to combinatorial explosion levels of copying the function’s code, once again making the binary size blow up

Debug mode is very reluctant to inline functions, if you go to [https://godbolt.org](https://godbolt.org) you’ll find that in debug mode the functions in std/start.zig get preserved as functions (even though they’re called only once), whereas in any release mode they’ll get inlined

---

<div class="post-metadata">

**Author:** ![WeeBull](https://ziggit.dev/user_avatar/ziggit.dev/weebull/32/6828_2.png) [@WeeBull](https://ziggit.dev/u/WeeBull)\
**Post date:** [November 20, 2026, 11:59am UTC](https://ziggit.dev/t/function-inlining-questions/18529/6 "2026-11-20T11:59:03Z")

</div>

I’m not sure if you’re wanting to make sure something isn’t inlined, so I think it’s worth mentioning the `noinline` keyword. It’s not mentioned in the language docs, apart from the keyword table. It stops a function from being able to be automatically inlined.

It’s rare that you need it, but I have found it useful on occasions.
