Skip to content

perf(hashmap): fix from_array to avoid mid-build rehashing#3330

Merged
bobzhang merged 1 commit intomainfrom
perf/hashmap-from-array-capacity
Mar 23, 2026
Merged

perf(hashmap): fix from_array to avoid mid-build rehashing#3330
bobzhang merged 1 commit intomainfrom
perf/hashmap-from-array-capacity

Conversation

@bobzhang
Copy link
Copy Markdown
Contributor

@bobzhang bobzhang commented Mar 23, 2026

Summary

  • from_array was creating the initial table with capacity=arr.length(), but the map grows at 50% load factor. This meant construction always triggered a rehash after inserting only half the elements.
  • Fix: use capacity=arr.length()*2.

Test plan

  • moon test -p moonbitlang/core/hashmap passes (115/115 tests)

🤖 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 3153

Details

  • 1 of 1 (100.0%) changed or added relevant line in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 95.721%

Totals Coverage Status
Change from base Build 3151: 0.0%
Covered Lines: 13825
Relevant Lines: 14443

💛 - Coveralls

Copy link
Copy Markdown

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 2 additional findings.

Open in Devin Review

@bobzhang bobzhang force-pushed the perf/hashmap-from-array-capacity branch from 6f22b48 to 4a578ba Compare March 23, 2026 09:18
from_array was creating the initial table with capacity=arr.length(),
but the map grows at 50% load factor. This meant construction would
always trigger a rehash after inserting only half the elements.

Fix: use capacity=arr.length()*2 so all input entries fit without
triggering the grow threshold during construction.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@bobzhang bobzhang force-pushed the perf/hashmap-from-array-capacity branch from 4a578ba to 0dc0f9b Compare March 23, 2026 10:48
@bobzhang bobzhang enabled auto-merge (rebase) March 23, 2026 10:48
@bobzhang bobzhang merged commit 31918c4 into main Mar 23, 2026
14 checks passed
@bobzhang bobzhang deleted the perf/hashmap-from-array-capacity branch March 23, 2026 10: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