Are nested withContext calls of equal type no-ops?

Suppose that a suspend function foobar() is called. Inside that function, withContext(NonCancellable) is used. And, foobar() itself is also called inside a withContext(NonCancellable) block.

In such a case, is the inner withContext(NonCancellable) block (= the one inside foobar()) a no-op? Or do such constructs incur a small performance hit?

And if we for example replace NonCancellable with a certain dispatcher (in both the outer and the inner withContext block), is the behavior different? Is a duplicate inner withContext block a no-op only with some context types, with none, or with all…?

1 Like