Skip to content

Test: GC allocation assertion for simulation hotpath#20

Merged
Ghostmonday merged 1 commit into
mainfrom
gc-allocation-tests-11326902386341427143
Jun 10, 2026
Merged

Test: GC allocation assertion for simulation hotpath#20
Ghostmonday merged 1 commit into
mainfrom
gc-allocation-tests-11326902386341427143

Conversation

@Ghostmonday

Copy link
Copy Markdown
Owner

Implemented a GC allocation assertion test for the engine's TickPrediction simulation hotpath. To make the test pass and enforce the engine's zero-allocation guarantee, InputFrame was refactored to eliminate internal heap arrays by using an internal inline struct for inputs, and RollbackController was updated to pre-allocate states in the ring buffer.


PR created automatically by Jules for task 11326902386341427143 started by @Ghostmonday

- Added `GcAllocationTests` to measure and assert 0 byte allocations in `TickPrediction` hotpath.
- Refactored `InputFrame` to use a flat struct (`PlayerInputsArray` with `P0`-`P7`) instead of a `ushort[]` array to prevent per-frame array allocations.
- Fixed `RollbackController` to pre-allocate `GameState` in ring buffer at startup.
- Fixed `RollbackController` to re-use ring buffer frames correctly rather than calling `InputFrame.Empty` which created new structures.

Co-authored-by: Ghostmonday <207882092+Ghostmonday@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0aaa18c120

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +66 to +69
for (int i = 0; i < _maxFrames; i++)
{
_stateBuffer.Set(i, new GameState(_playerCount));
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve unset state slots when preallocating

Because this constructor now calls Set for every ring-buffer slot, RingBuffer.Has(frame) becomes true for every non-negative frame from startup due to modulo indexing. As a result, GetState(1) or GetState(999) on a fresh controller returns an unsimulated default snapshot instead of null, and callers can read hashes/state for frames that have never been executed. Preallocating storage should avoid marking future frame slots as occupied, or GetState/Has needs a real frame-number check.

Useful? React with 👍 / 👎.

Comment on lines +54 to +55
if (playerCount > 8)
throw new System.ArgumentOutOfRangeException(nameof(playerCount), "Max supported player count is 8");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve support for larger player counts

This new hard cap makes new InputFrame(frame, 9) and any replay frame with more than eight inputs throw, while the engine configuration and GameState still accept arbitrary PlayerCount values and the replay format stores playerCount as a variable length. Simulations or saved replays configured for 9+ players now fail during input creation/deserialization; either keep the previous arbitrary-count path or reject the limit consistently at the RollbackConfig/replay-header boundary.

Useful? React with 👍 / 👎.

@Ghostmonday Ghostmonday merged commit 0cd85db into main Jun 10, 2026
1 check 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.

1 participant