-
-
Notifications
You must be signed in to change notification settings - Fork 50
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
v2: conversion to utilize go1.18 generics #14
Conversation
Quick benchmarks show very minor but inconsistent performance improvements, a longer bake time looks like PickParallel might pick up 2-3% due to lack of type conversions on the hot path:
Confirming this is primarily an ergonomics change, rather than a performance one. |
Codecov Report
@@ Coverage Diff @@
## main #14 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 1 1
Lines 39 41 +2
=========================================
+ Hits 39 41 +2
Continue to review full report at Codecov.
|
Since v2 will break API compatibility it is a good time to consider any other ergonomic changes. One might be allowing the more common |
cd3b27e introduces an Might also require some documentation updates to specify how negative weights are handled (or not handled, since they are ignored). Needs validation of how things can be gracefully transitioned to use |
51345e7
to
8a10b41
Compare
Great package, enjoyed using it so far - so was keen to follow the generification - but ended up being impatient. With the use of an When using a fixed However, to allow for varadic input weight types, what I've done is introduce the concept of a domain-mapper function that maps from whatever numeric type I want to float64:
Then internally, its float64 to the moon. Any thoughts around something like this making it into the main code? Then in principle users can choose their poison on the weights. |
Very cool. I've thought about float support, but that would change some of the semantics of how the "score" works here conceptually: if I was going that direction, I'd might use a different algorithm (Vose's alias method) that is even faster I've been wrapping my head around, and put in a new library where I can change the API accordingly: https://www.keithschwarz.com/darts-dice-coins/ |
Needs perf testing and validation of how things can be gracefully transitioned to use contraints.Integer if it is introduced to stdlib at a later time. Might also require some documentation updates to specify how negative weights are handled (or not handled, since they are ignored).
This will improve the ergonomics of this library since we currently use an
interface{}
container type.However, that will require go1.18+, which will be a breaking change, thus the plan will be to roll a v1.0 release on the previous version, and do a v2.0 semantic release for this change (requiring an import path change for modules consumers).
Due to the mechanics of v2 releases in Go modules, this will require a bit of thinking as to how I will handle. For now, this branch/PR represents the playground for adding generics support.
(Additionally, I have experimental fuzz testing in the seperate
fuzz
branch, which may be rolled into here for the release as well.)