Closed Multramate closed 5 years ago
I think this is fine. What is the delta in performance with and without unsafeCoerce?
I think this is fine. What is the delta in performance with and without unsafeCoerce?
Without unsafeCoerce
, we would have to use fromInteger
, which does unnecessary slow modular reductions. Using the current benchmarks on my machine,
unsafeCoerce
, ~105ns with fromInteger
, andunsafeCoerce
, ~205ns with fromInteger
.I did not measure the other operations but their deltas are relatively negligible (e.g. division already takes ~1us, so nanosecond boosts are unnoticeable). Essentially, there is a minor boost in performance in all fronts, but with higher robustness due to abstracting low-level optimisations completely to mod
.
Alternatively, we could request for Mod
to be exposed in Data.Mod.Unsafe
, for instance.
Ok sounds good to me.
Pull Request Checklist