π€ AI Summary
PBT generators suffer from performance bottlenecks primarily due to high overhead from combinator abstractions and inefficient random source implementations, limiting both test-case generation throughput and bug detection rate. This paper introduces the first systematic application of multi-stage programming (Allegro) to optimize PBT generators: (1) leveraging meta-programming (in OCaml/Scala 3) to eliminate combinator runtime abstraction overhead, and (2) integrating high-performance pseudorandom number generation (e.g., Xorshift) with semantics-preserving generator recompilation. It presents the first quantitative, decoupled empirical analysis validating the independent impacts of abstraction overhead and randomness efficiency on PBT performance. Evaluated on mainstream OCaml and Scala 3 PBT libraries, the approach achieves up to 13Γ speedup in generator execution while simultaneously increasing bug-finding rate by 13Γ per unit timeβall without altering the original generator semantics.
π Abstract
Property-based testing (PBT) relies on generators for random test cases, often constructed using embedded domain specific languages, which provide expressive combinators for building and composing generators. The effectiveness of PBT depends critically on the speed of these generators. However, careful measurements show that the generator performance of widely used PBT libraries falls well short of what is possible, due principally to (1) the abstraction overhead of their combinator-heavy style and (2) suboptimal sources of randomness. We characterize, quantify, and address these bottlenecks. To eliminate abstraction overheads, we propose a technique based on multi-stage programming, dubbed Allegro. We apply this technique to leading generator libraries in OCaml and Scala 3, significantly improving performance. To quantify the performance impact of the randomness source, we carry out a controlled experiment, replacing the randomness in the OCaml PBT library with an optimized version. Both interventions exactly preserve the semantics of generators, enabling precise, pointwise comparisons. Together, these improvements find bugs up to $13 imes$ faster.