jberryman / unagi-chan

A haskell library implementing fast and scalable concurrent queues for x86, with a Chan-like API
BSD 3-Clause "New" or "Revised" License
127 stars 15 forks source link

GHC doesn't do floating point constant folding #5

Closed kvanbere closed 10 years ago

kvanbere commented 10 years ago

In the source there are some constants which have type Float wrapped in round. GHC doesn't do any form of Float constant folding yet, so you should hand-calculate these into Int (and probably leave the original ones commented out above) for a tiny speed bonus.

jberryman commented 10 years ago

Thanks for the feedback, kvanberendonck. I think all those instances are in top-level constants which I'm not worried about. If they're being calculated more than once then I have much bigger problems! Closing for now, but please let me know if you find any other issues looking at the core or benchmarking.

kvanbere commented 10 years ago

Sure, just means whatever is using it will have an extra branch to see if it needs forcing since it won't be inlined+strictified. If it does get inlined into i.e. moveToNextCell, you'd be in trouble.

I'll do a core inspection for you tonight. I think you closed this too promptly imo.

jberryman commented 10 years ago

Yeah, you're right, thanks; re-opening so I remember to look into this later. I initially had plans to make sEGMENT_LENGTH configurable, but I'm not sure that's necessary. I might just hard-code the values and assert that they equal the calculated value or something.

kvanbere commented 10 years ago

After inspecting core, GHC does not inline the floating point operations in the constants. Still persue if you want the tiny speedup for the constants being strict, otherwise it's safe to close for now probably.