Skip to content

Conversation

@kcbanner
Copy link
Contributor

Before this change, the following sequence of events was possible:

  1. The current free queue storage region (between head and tail) wraps around the end of the array
  2. An entry is added via didGetNewHandleNoResize, which resizes the free queue backing slice
  3. The region between head and tail now contains an undefined entry

I initially fixed this by always preferring to use entries from the free list, but the problem with that solution is that a smaller number of indices are used, and their cycle counts are incremented more often, which would increase the chances of a stale handle accidentally aliasing a re-used handle.

This new strategy is to prefer entries from the free list only if it spans past the end of the storage buffer, and to prefer unused entries otherwise.

…ree queue storage is resized.

Before this change, the following sequence of events was possible:
1. The current free queue storage region (between head and tail) wraps around the end of the array
2. An entry is added via `didGetNewHandleNoResize`, which resizes the free queue backing slice
3. The region between head and tail now contains an undefined entry

I initially fixed this by always preferring to use entries from the free list, but the problem with that solution
is that a smaller number of indices are used, and their cycle counts are incremented more often, which
would increase the chances of a stale handle accidentally aliasing a re-used handle.

This new strategy is to prefer entries from the free list only if it spans past the end of the storage buffer,
and to prefer unused entries otherwise.
@kcbanner kcbanner force-pushed the fixup_ring_buffer_resize branch from 19e1552 to 06e4000 Compare April 19, 2025 20:00
@hazeycode hazeycode requested review from hazeycode and removed request for hazeycode April 20, 2025 21:12
Copy link
Member

@hazeycode hazeycode left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice job! Looks good to me.

Note to self: We should devise benchmarks and more stress tests so we can better evaluate the impact of changes like this one.

@hazeycode hazeycode merged commit 4c850e2 into zig-gamedev:main May 7, 2025
3 checks passed
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