# When to make dirty NIFs?

**URL:** <https://erlangforums.com/t/when-to-make-dirty-nifs/1711>\
**Category:** Questions / Help\
**Tags:** erts, nif, erlang-otp\
**Created:** [August 3, 2022, 4:26pm UTC](https://erlangforums.com/t/when-to-make-dirty-nifs/1711 "2022-08-03T16:26:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![nhpip](https://erlangforums.com/letter_avatar_proxy/v4/letter/n/3bc359/32.png) [@nhpip](https://erlangforums.com/u/nhpip)\
**Post date:** [August 3, 2022, 4:26pm UTC](https://erlangforums.com/t/when-to-make-dirty-nifs/1711/1 "2022-08-03T16:26:31Z")

</div>

Hi,

I have a NIF where profiling indicates some functions are hovering around the 1ms region so I intend to make them dirty. Should I just make those functions dirty, or should I do it for all of them? Is there a disadvantage in making a fast NIF function dirty when it doesn’t need to be?

Thanks

---

<div class="post-metadata">

**Author:** ![garazdawi](https://erlangforums.com/user_avatar/erlangforums.com/garazdawi/32/175_2.png) [@garazdawi](https://erlangforums.com/u/garazdawi)\
**Post date:** [August 3, 2022, 6:33pm UTC](https://erlangforums.com/t/when-to-make-dirty-nifs/1711/2 "2022-08-03T18:33:40Z")

</div>

> [@nhpip](#):
>
> Is there a disadvantage in making a fast NIF function dirty when it doesn’t need to be?

There is a small performance cost as the process needs to be re-scheduled on another scheduler to do the dirty work. How much it costs will vary depending on lots of factors, so you should benchmark your case and see if it matters in the big scheme of things.

---

<div class="post-metadata">

**Author:** ![nhpip](https://erlangforums.com/letter_avatar_proxy/v4/letter/n/3bc359/32.png) [@nhpip](https://erlangforums.com/u/nhpip)\
**Post date:** [August 3, 2022, 8:23pm UTC](https://erlangforums.com/t/when-to-make-dirty-nifs/1711/3 "2022-08-03T20:23:47Z")

</div>

Thanks, it’s safe to have some functions dirty and others not then?

---

<div class="post-metadata">

**Author:** ![garazdawi](https://erlangforums.com/user_avatar/erlangforums.com/garazdawi/32/175_2.png) [@garazdawi](https://erlangforums.com/u/garazdawi)\
**Post date:** [August 4, 2022, 11:32am UTC](https://erlangforums.com/t/when-to-make-dirty-nifs/1711/4 "2022-08-04T11:32:55Z")

</div>

> [@nhpip](#):
>
> it’s safe to have some functions dirty and others not then?

yes it is.
