Skip to content

perf(quickcheck): build arbitrary strings linearly - #4148

Merged
bobzhang merged 1 commit into
moonbitlang:mainfrom
mizchi:perf/quickcheck-string-builder
Aug 25, 2026
Merged

perf(quickcheck): build arbitrary strings linearly#4148
bobzhang merged 1 commit into
moonbitlang:mainfrom
mizchi:perf/quickcheck-string-builder

Conversation

@mizchi

@mizchi mizchi commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Build arbitrary strings with StringBuilder instead of repeatedly concatenating one character at a time. This changes construction from quadratic copying to a linear append loop while preserving random-state consumption and generated values.

Native benchmark (size=10000, 100 generated strings):

before after change
84.85 ms 3.26 ms 96% faster

Validation: all 82 QuickCheck tests pass on wasm, wasm-gc, JS, and native; moon check --target all and moon info pass.

Copilot AI lite review requested due to automatic review settings August 24, 2026 18:29

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Improves QuickCheck’s Arbitrary implementation for String by switching from repeated string concatenation (quadratic copying) to a StringBuilder append loop (linear construction), and adds a benchmark test to track the performance win.

Changes:

  • Refactor Arbitrary for String to build via StringBuilder.write_char and a final to_string().
  • Add a dedicated benchmark test for generating 100 strings at size 10,000.
  • Add moonbitlang/core/bench as a test-only dependency for the quickcheck package.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
quickcheck/moon.pkg Adds bench as a test-only import to support the new benchmark test.
quickcheck/arbitrary.mbt Replaces per-character string concatenation with StringBuilder to make generation linear-time.
quickcheck/arbitrary_string_bench_test.mbt Introduces a benchmark test to measure Arbitrary String generation performance.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@bobzhang
bobzhang merged commit b91f766 into moonbitlang:main Aug 25, 2026
13 of 16 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.

3 participants