Skip to content

fix(hunty-core): remove O(n) scan in add_player_to_list on progress save - #1189

Merged
Samuel1-ona merged 1 commit into
Samuel1-ona:mainfrom
JesseJohn7:fix/1049-add-player-to-list-scan
Sep 30, 2026
Merged

Samuel1-ona merged 1 commit into
Samuel1-ona:mainfrom
JesseJohn7:fix/1049-add-player-to-list-scan

Conversation

@JesseJohn7

Copy link
Copy Markdown

Closes #1049

Problem

save_player_progress runs on every answer, hint and claim and calls
add_player_to_list. When the player's existence marker was present, the
function looped over indices 0..count reading each entry until it found the
player. Every submission therefore cost O(players) storage reads, making large
hunts effectively unplayable.

Fix

  • add_player_to_list now trusts the existence marker: if it is set, the
    function returns immediately. No scan.
  • Applied the same change at the second occurrence (storage.rs ~L1456-1483).
  • The marker is written in the same code path that appends to the list, so it
    is an accurate signal of membership.

Benchmark

Added bench_save_progress_500_players in test.rs. It registers 500 players,
then measures the CPU instruction cost of a single progress save for the
last-registered player (worst case for the old implementation) and asserts it
stays under a fixed ceiling.

CPU instructions
Before
After

Testing

  • cargo test -p hunty-core passes
  • cargo fmt / cargo clippy clean

Acceptance criteria

  • Trust the existence marker and skip the scan
  • Benchmark with 500 players

@Samuel1-ona
Samuel1-ona merged commit 2381f60 into Samuel1-ona:main Sep 30, 2026
1 check passed
Samuel1-ona pushed a commit that referenced this pull request Oct 2, 2026
- hunty-core: restore `list_clues_for_hunt`, which PR #1189 accidentally
  replaced with a half-written stub, leaving storage.rs unparsable.
- hunty-core: wire the documented `MIN_INVITE_CODE_LENGTH` into
  `generate_invite_code` and stop ignoring `add_co_creator`'s Result.
- reward-manager: thread the explicit `caller` argument the #1061 refactor
  added to `distribute_rewards` through `distribute_rewards_legacy` and
  `distribute_proportional`, and update the affected test call sites.
- Reformat the workspace with rustfmt; refresh docs/contract-api.md and
  docs/STORAGE_KEYS.md.
- CI: opt the wasm build steps into the Stellar spec-shaking build system
  required by soroban-sdk 28.
- npm audit fix for the ip-address advisory.

🤖 Generated with Codebuff
Co-Authored-By: Codebuff <noreply@codebuff.com>
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.

hunty-core: add_player_to_list scans every registered player on each progress save

2 participants