Skip to content

perf: optimize buffer selection with pointer hashing and fast-path#772

Open
wicyn wants to merge 1 commit intotaskflow:masterfrom
wicyn:master
Open

perf: optimize buffer selection with pointer hashing and fast-path#772
wicyn wants to merge 1 commit intotaskflow:masterfrom
wicyn:master

Conversation

@wicyn
Copy link
Contributor

@wicyn wicyn commented Mar 18, 2026

Description

This PR optimizes the _spill and _bulk_spill logic in the Executor to reduce contention and improve performance.

Key Changes:

  • Optimized Index Generation: Implemented Fibonacci hashing on node pointers to ensure a more uniform distribution.
  • Efficient Modulo Calculation: Added a fast-path for power-of-two buffer sizes using bitwise AND (size - 1).
  • Lock-Avoidance Fast-Path: Introduced a linear probe that attempts try_lock on all buffers before falling back to a blocking wait.

These changes significantly reduce synchronization overhead when multiple threads are spilling tasks simultaneously.

Refactored the spill logic to improve performance under high contention.
Key changes include:

1. Optimized Index Generation: Implemented Fibonacci hashing on
   node pointers to ensure a more uniform distribution across buffers.
2. Efficient Modulo Calculation: Added a fast-path for power-of-two
   buffer sizes using bitwise AND, significantly reducing CPU cycles.
3. Lock-Avoidance Fast-Path: Introduced a non-blocking search that
   probes all buffers with try_lock before falling back to a blocking wait.
@tsung-wei-huang
Copy link
Member

@wicyn thank you for the pull request. Do you have any measured runtime difference between this pull and the original one? I feel this is significantly more complex, not sure about its practical benefit. Say, do you see any unittest runtime difference?

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.

2 participants