-
Notifications
You must be signed in to change notification settings - Fork 44
Reintroduce Shrink.list_spine optimization #283
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
89852fb to
1b3e1a0
Compare
|
Rebased on |
|
Another possibility would be: if (try x <> y with Invalid_argument _ -> x != y) then ... |
|
Ha! That's an interesting suggestion... To better understand, I tried the suggestion and reran the test suite to spot which other optimizations it would pick up and report as expect-test and unit-test failures. The result was a none however. This indicates a test suite short-coming, as it should make a difference when shrinking heap allocated data, say I also reran the shrinker benchmark (details in unfolding below):
Overall
iteration seed 1234 iteration seed 8743 iteration seed 6789 total
Shrink test name Q1/s #succ/#att Q2/s #succ/#att Q1/s #succ/#att Q2/s #succ/#att Q1/s #succ/#att Q2/s #succ/#att Q1/s Q2/s
< bind list_size constant 0.000 52/230 0.000 12/25 0.000 49/227 0.000 9/19 0.000 43/192 0.000 10/19 0.000 0.000
< lists shorter than 10 0.000 49/315 0.000 15/24 0.000 50/315 0.000 17/34 0.000 36/236 0.000 13/28 0.000 0.000
< lists shorter than 432 0.184 1738/20737 0.738 413/448 0.100 1667/19905 0.312 419/461 0.185 1712/20417 0.686 422/471 0.470 1.736
---
> bind list_size constant 0.000 52/207 0.000 12/25 0.000 49/204 0.000 9/19 0.000 43/171 0.000 10/19 0.000 0.000
> lists shorter than 10 0.000 49/279 0.000 15/24 0.000 50/282 0.000 17/34 0.000 36/210 0.000 13/28 0.000 0.000
> lists shorter than 432 0.178 1738/19018 0.739 413/448 0.104 1667/18254 0.287 419/461 0.187 1712/18727 0.661 422/471 0.469 1.687As such, I lean towards going with the proposed change for now as it gets us a nice improvement on some list shrinking situations at an affordable complexity. Full benchmark detailsmainthis PRabove suggestion |
|
On second thought, there's something nice about the shrinker avoiding redundant candidates equally well on unboxed and boxed data types without an end-user having to worry about the difference. Generally I would expect a property to be more costly than a |
This little PR reintroduces a small optimization to
Shrink.list_spinethat had to be rolled back in #280.The reason was that the polymorphic difference (inequality?) operator
<>would fail when comparing list elements with function values:Kudos to @shym for suggesting a simple fix: use an address comparison
!=instead!On the one hand this
test_list_spine_compareOn the other hand, it doesn't identify as many equalities since, e.g., identical strings don't necessarily live at the same address 🤷