# Why is enif\_consume\_timeslice/2 a no-op on dirty schedulers since OTP 22?

**URL:** <https://erlangforums.com/t/why-is-enif-consume-timeslice-2-a-no-op-on-dirty-schedulers-since-otp-22/5793>\
**Category:** Questions / Help\
**Tags:** erlang, nif\
**Created:** [July 18, 2026, 7:59pm UTC](https://erlangforums.com/t/why-is-enif-consume-timeslice-2-a-no-op-on-dirty-schedulers-since-otp-22/5793 "2026-07-18T19:59:07Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![zabrane](https://erlangforums.com/letter_avatar_proxy/v4/letter/z/7ba0ec/32.png) [@zabrane](https://erlangforums.com/u/zabrane)\
**Post date:** [July 18, 2026, 7:59pm UTC](https://erlangforums.com/t/why-is-enif-consume-timeslice-2-a-no-op-on-dirty-schedulers-since-otp-22/5793/1 "2026-07-18T19:59:07Z")

</div>

Between `OTP 21` and `OTP 22`, [enif\_consume\_timeslice/2](https://github.com/erlang/otp/blob/OTP-29.0/erts/emulator/beam/erl_nif.c#L3339-L3358) gained an early return on dirty schedulers:

```c
if (sched < 0)
    return 0; /* no-op on dirty scheduler */

```

Before, it worked identically on normal and dirty. The documented well-behaved-NIF pattern (call `enif_consume_timeslice`, on non-zero call `enif_schedule_nif`) is now silently broken for dirty NIFs, the return branch never fires. Also, reductions are no longer credited for CPU time spent on dirty schedulers.

Concrete case: an on-device LLM inference NIF. When the number of concurrent sessions exceeds the dirty CPU scheduler count, queued sessions must wait for a full forward pass to complete before making any progress, since the pre-emption granularity is one whole NIF call. Pre-OTP-22, the C side could yield mid-forward-pass via enif\_consume\_timeslice + enif\_schedule\_nif, so all sessions would advance concurrently at roughly (scheduler\_count / session\_count) of full speed.

Was `pre-OTP-22` behavior considered incorrect? And is elapsed-based enif\_schedule\_nif with DIRTY\_JOB\_\* flags (ignoring enif\_consume\_timeslice’s return) the intended replacement now?

Zab.

---

<div class="post-metadata">

**Author:** ![jhogberg](https://erlangforums.com/user_avatar/erlangforums.com/jhogberg/32/179_2.png) [@jhogberg](https://erlangforums.com/u/jhogberg)\
**Post date:** [July 19, 2026, 9:26pm UTC](https://erlangforums.com/t/why-is-enif-consume-timeslice-2-a-no-op-on-dirty-schedulers-since-otp-22/5793/2 "2026-07-19T21:26:18Z")

</div>

> [@zabrane](#):
>
> Was `pre-OTP-22` behavior considered incorrect?

Yes, reductions aren’t a thing on dirty schedulers, and reading the old code it was buggy on top of it all.

If you want the old behavior minus the bug, you can replicate it by declaring `int reds = 100;` and decrementing it towards `0` yourself in your NIF.
