perf(lib): acquire capture lists from a free stack instead of scanning
The Issue & Context
Previously, acquiring a capture list required scanning the entire pool to find a free list, resulting in O(pool size) complexity. This caused severe slowdowns in queries holding many capture lists, as the pool size grew with the match limit.
Root Cause Analysis
The capture_list_pool_acquire function performed a linear search over the pool to find a free capture list, making acquisition costly and inefficient when many capture lists were in use.
Solution Strategy & Architectural Pattern
Replaced the linear scan with a free stack that tracks free capture list IDs, enabling constant time push on release and pop on acquire, drastically reducing acquisition overhead.
Key Takeaway for Contributors
Maintaining explicit free resource stacks can significantly improve performance over scanning large pools, especially in systems with many concurrent states or allocations.