-
Notifications
You must be signed in to change notification settings - Fork 2
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
Implement Control.Concurrent.Counter.Unlifted in CMM #3
Conversation
Hmm, tests are failing on GHC 9.4.4, macOS x86_64:
Whatever the sequence of updates, the result must have been below five digits, so @TerrorJack, any idea where I messed up? |
Great! I was just thinking about this too. Thanks @Bodigrim |
Pong, will take a closer look next week. |
I'm also interested in seeing this work, don't mind my second ping @TerrorJack |
Would you give https://gist.github.com/TerrorJack/e3f1231fa65b3d1f5ea63065dd33a87f a try and see if it fixes the issue? Honestly I'm no less puzzled than you why the original version has this memory issue, but this diff seems to help. |
Thanks @TerrorJack, this seems to work. I think this is ready for review now. |
FWIW LGTM |
Benchmarks:
Interestingly the biggest speed up, up to 25%, is observed for 1000 iterations, while measurements for 10000 iterations are consistently better, but less impressive, up to 11%. |
Impressive, thanks a lot! |
NB for comparison of CMM against mutable prim array one can compare against |
Released as |
Just an experiment to avoid any overhead for
MutableByteArray
inspired by @TerrorJack's https://gist.github.com/TerrorJack/4a48ed790155cc79619fffe9f5844521.Caveats:
Does not work in GHC JavaScript backend, which should probably retain the previous, pure Haskell implementation.Needs more care on 32-bit machines, current code is 64 bit only.
ccall hs_atomic_add64
is suboptimal onx86_64
, but at the moment hand-written CMM cannot accesscall MO_AtomicRMW W64 AMO_Add
, see https://gitlab.haskell.org/ghc/ghc/-/issues/23206.