Skip to content

perf(hashset): fix from_array capacity and make shift_back iterative#3334

Open
bobzhang wants to merge 2 commits intomainfrom
perf/hashset-capacity-and-shift-back
Open

perf(hashset): fix from_array capacity and make shift_back iterative#3334
bobzhang wants to merge 2 commits intomainfrom
perf/hashset-capacity-and-shift-back

Conversation

@bobzhang
Copy link
Copy Markdown
Contributor

@bobzhang bobzhang commented Mar 23, 2026

Summary

  • from_array: pre-allocate with capacity=arr.length()*2 instead of default capacity 8, avoiding multiple grow operations during construction.
  • shift_back: convert from recursive to iterative loop to prevent stack overflow at high load factors.

Test plan

  • moon test -p moonbitlang/core/hashset — all 65 tests pass

🤖 Generated with Claude Code


Open with Devin

@coveralls
Copy link
Copy Markdown
Collaborator

coveralls commented Mar 23, 2026

Pull Request Test Coverage Report for Build 3172

Details

  • 11 of 11 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.001%) to 95.554%

Totals Coverage Status
Change from base Build 3171: 0.001%
Covered Lines: 14078
Relevant Lines: 14733

💛 - Coveralls

devin-ai-integration[bot]

This comment was marked as resolved.

@bobzhang bobzhang force-pushed the perf/hashset-capacity-and-shift-back branch from 20f6de6 to 7c4b0d1 Compare March 23, 2026 09:18
bobzhang and others added 2 commits March 25, 2026 21:55
- from_array: pre-allocate with capacity=arr.length()*2 instead of
  default capacity 8. This avoids multiple grow operations during
  construction (e.g., a 100-element array was triggering 5 consecutive
  grow cycles: 8->16->32->64->128->256).

- shift_back: convert from recursive to iterative loop. With 81%
  load factor, pathological hash collision patterns could create
  deep probe sequences, making the recursive version vulnerable
  to stack overflow on large tables.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@bobzhang bobzhang force-pushed the perf/hashset-capacity-and-shift-back branch from 7c4b0d1 to d2c77e7 Compare March 25, 2026 13:55
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