perf(quickcheck): build arbitrary strings linearly - #4148
Merged
Conversation
Contributor
There was a problem hiding this comment.
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 Stringto build viaStringBuilder.write_charand a finalto_string(). - Add a dedicated benchmark test for generating 100 strings at size 10,000.
- Add
moonbitlang/core/benchas a test-only dependency for thequickcheckpackage.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Build arbitrary strings with
StringBuilderinstead 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):Validation: all 82 QuickCheck tests pass on wasm, wasm-gc, JS, and native;
moon check --target allandmoon infopass.