# Kwargs... and allocations

**URL:** <https://discourse.julialang.org/t/kwargs-and-allocations/129183>\
**Category:** Performance\
**Tags:** allocations\
**Created:** [May 20, 2025, 5:19pm UTC](https://discourse.julialang.org/t/kwargs-and-allocations/129183 "2025-05-20T17:19:23Z")\
**Posts on this page:** 7\
**Page:** 2

<div class="post-metadata">

**Author:** ![simsurace](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/simsurace/32/30216_2.png) [@simsurace](https://discourse.julialang.org/u/simsurace)\
**Post date:** [May 20, 2025, 7:38pm UTC](https://discourse.julialang.org/t/kwargs-and-allocations/129183/21 "2025-05-20T19:38:47Z")

</div>

Why not use singleton structs?

---

<div class="post-metadata">

**Author:** ![Allan\_Baker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/allan_baker/32/42645_2.png) [@Allan\_Baker](https://discourse.julialang.org/u/Allan_Baker)\
**Post date:** [May 20, 2025, 9:38pm UTC](https://discourse.julialang.org/t/kwargs-and-allocations/129183/22 "2025-05-20T21:38:47Z")

</div>

I am not. Thank you! I will check that out.

---

<div class="post-metadata">

**Author:** ![Allan\_Baker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/allan_baker/32/42645_2.png) [@Allan\_Baker](https://discourse.julialang.org/u/Allan_Baker)\
**Post date:** [May 20, 2025, 9:41pm UTC](https://discourse.julialang.org/t/kwargs-and-allocations/129183/23 "2025-05-20T21:41:51Z")

</div>

> [@simsurace](#):
>
> structs

Why not indeed! Because I had forgotten all about them and unfortunately the first thing I thought of was an abstract type. I like it. I will move over to that. It looks like it may be better. Is there a disadvantage?

---

<div class="post-metadata">

**Author:** ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)\
**Post date:** [May 20, 2025, 9:52pm UTC](https://discourse.julialang.org/t/kwargs-and-allocations/129183/24 "2025-05-20T21:52:18Z")

</div>

> [@Allan\_Baker](#):
>
> Is there a disadvantage?

Nope, not to my knowledge. This is the pattern that Julia itself uses in many many places (see, e.g., `IndexLinear()` and `Base.HasEltype()` and `Val(_)` instead of `Val{_}` and more) so you’re on the happy path.

---

<div class="post-metadata">

**Author:** ![Allan\_Baker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/allan_baker/32/42645_2.png) [@Allan\_Baker](https://discourse.julialang.org/u/Allan_Baker)\
**Post date:** [May 20, 2025, 9:56pm UTC](https://discourse.julialang.org/t/kwargs-and-allocations/129183/25 "2025-05-20T21:56:30Z")

</div>

Love the Julia community! Thank you all of teaching me 3 or 4 new tricks today!

---

<div class="post-metadata">

**Author:** ![Allan\_Baker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/allan_baker/32/42645_2.png) [@Allan\_Baker](https://discourse.julialang.org/u/Allan_Baker)\
**Post date:** [May 21, 2025, 3:26am UTC](https://discourse.julialang.org/t/kwargs-and-allocations/129183/26 "2025-05-21T03:26:37Z")

</div>

I do seem to still get allocations, even after switching to singleton structs when I am just using named variables at all in the functions after the semicolon and I don’t use the splats and slerps. Using the settings structure seems to be the only solution that is giving me no allocations. The @check\_allocs still gives me 1 dynamic dispatch even on the settings method, which gives no allocations.

---

<div class="post-metadata">

**Author:** ![mikmoore](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mikmoore/32/31109_2.png) [@mikmoore](https://discourse.julialang.org/u/mikmoore)\
**Post date:** [May 21, 2025, 3:05pm UTC](https://discourse.julialang.org/t/kwargs-and-allocations/129183/27 "2025-05-21T15:05:49Z")

</div>

A singleton struct shouldn’t be worse than a settings struct (think of it as a settings struct with 0 fields). Are you using `SingletonStruct` (the type)? Be sure you’re using `SingletonStruct()` (an instance) as your argument, as the type still comes with all the caveats of the types discussed above.

[Previous page](https://discourse.julialang.org/t/kwargs-and-allocations/129183.md?page=1)
