perf(quickcheck): execute zipped generators directly - #4147
Open
mizchi wants to merge 2 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR optimizes @quickcheck.Generator composition by implementing Generator::zip_with and Generator::zip_with3 directly, avoiding per-sample allocation overhead from flat_map/map composition while preserving the same RandomState::split() sequencing semantics.
Changes:
- Implement
Generator::zip_withvia a single generator closure that splits state once and runs both generators directly. - Implement
Generator::zip_with3directly, matching the previous nested-flat_mapstate-splitting behavior. - Add a benchmark-style test for
Generator::zip_withand wire in thebenchdependency for tests.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| quickcheck/moon.pkg | Adds moonbitlang/core/bench as a test-only import to support benchmark tests. |
| quickcheck/generator.mbt | Replaces composed flat_map/map implementations of zip_with/zip_with3 with direct implementations to reduce allocation/closure overhead. |
| quickcheck/generator_bench_test.mbt | Adds a benchmark test exercising Generator::zip_with for performance tracking. |
💡 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.
Implement
Generator::zip_withandzip_with3directly instead of composingflat_mapandmap. The previous composition allocated temporary generators and closures for every generated sample.The state splitting and evaluation order are preserved.
Native benchmark (
zip_with, 1,000,000 samples):Validation: all 82 QuickCheck tests pass on wasm, wasm-gc, JS, and native;
moon check --target allandmoon infopass.