Skip to content

par_sort_pairs: Use a growable pool of thread states#164

Open
progval wants to merge 2 commits intovigna:mainfrom
progval:par_sort_pairs-crossbeam
Open

par_sort_pairs: Use a growable pool of thread states#164
progval wants to merge 2 commits intovigna:mainfrom
progval:par_sort_pairs-crossbeam

Conversation

@progval
Copy link
Contributor

@progval progval commented Feb 3, 2026

It turns out that rayon can return Yield::Idle when there is an other task running the the same thread (lower in the call stack), because it cannot yield to that other task (it would need to jump back to that point of the call stack, then back to where we currently are). This means that we need a way to add new states somehow.

Instead of creating throwaway states (which would create many tiny BatchIterators we would have to merge with the others) or making each thread have a pool of throwaway states (which would create fewer of them, but still many because the extra ones can't be used by other states), this introduces a global pool with all states in it.

This does add synchronization overhead, but it should be negligeable because try_for_each_init calls this initializer only once per internal sequential iterators; and if there are many small such iterators, then rayon already adds too much overhead anyway.

It turns out that rayon can return Yield::Idle when there is an other task running the the same thread (lower in the call stack),
because it cannot yield to that other task (it would need to jump back to that point of the call stack, then back to where we currently are).
This means that we need a way to add new states somehow.

Instead of creating throwaway states (which would create many tiny BatchIterators we would have to merge with the others)
or making each thread have a pool of throwaway states (which would create fewer of them, but still many because the extra ones can't be used by other states),
this introduces a global pool with all states in it.

This does add synchronization overhead, but it should be negligeable because try_for_each_init calls this initializer only once per internal sequential iterators;
and if there are many small such iterators, then rayon already adds too much overhead anyway.
This would cause us to silently lose data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant