Skip to content

perf(quickcheck): execute zipped generators directly - #4147

Open
mizchi wants to merge 2 commits into
moonbitlang:mainfrom
mizchi:perf/quickcheck-direct-zip
Open

perf(quickcheck): execute zipped generators directly#4147
mizchi wants to merge 2 commits into
moonbitlang:mainfrom
mizchi:perf/quickcheck-direct-zip

Conversation

@mizchi

@mizchi mizchi commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Implement Generator::zip_with and zip_with3 directly instead of composing flat_map and map. 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):

before after change
38.66 ms 11.64 ms 70% 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:26

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

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_with via a single generator closure that splits state once and runs both generators directly.
  • Implement Generator::zip_with3 directly, matching the previous nested-flat_map state-splitting behavior.
  • Add a benchmark-style test for Generator::zip_with and wire in the bench dependency 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.

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