perf(quickcheck): execute zipped generators directly - #4147
Conversation
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.
Coverage Report for CI Build 6572Coverage increased (+0.004%) to 89.244%Details
Uncovered ChangesNo uncovered changes found. Coverage RegressionsNo coverage regressions found. Coverage Stats
💛 - Coveralls |
41cf30a to
c511bfa
Compare
|
Reviewed and verified locally on The equivalence claim checks out. I diffed the new implementations against the old The one real reordering is in One thing worth recording, since the value-level diff cannot see it: Numbers reproduce. Everything else is clean. Only nit, not worth holding the PR for: there is a benchmark for |
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.