Open oberblastmeister opened 2 years ago
I bet we could implement delete
in terms of alter
with some inlining.
I bet we could implement
delete
in terms ofalter
with some inlining.
Probably. My inclination is not to rely on GHC optimizations more than necessary though.
Also, wouldn't this increase the size of the unfolding and thereby make it less likely that delete
is inlined in user code?!
My inclination is not to rely on GHC optimizations more than necessary though.
I think these are very simple optimizations, beta reduction and case simplification, which are performed by the ghc simplifier, and I am pretty sure these are very likely to fire. We also rely on these sorts of optimizations throughout the library anyways. It doesn't matter that much though, but would reduce a lot of code duplication, as alter
is pretty much a direct copy of delete
.
Why would this increase the size of the unfolding?
Sorry for the late response!
My inclination is not to rely on GHC optimizations more than necessary though.
I think these are very simple optimizations, beta reduction and case simplification, which are performed by the ghc simplifier, and I am pretty sure these are very likely to fire. We also rely on these sorts of optimizations throughout the library anyways. It doesn't matter that much though, but would reduce a lot of code duplication, as
alter
is pretty much a direct copy ofdelete
.
I think this means that GHC will need to spend more cycles on optimizing usage of delete
in user code. So the effect will be an increase in compile time and possibly a failure to perform other optimization once GHC runs out of simplifier iterations.
Feel free to give it a try in a follow-up PR though. I'm curious what effects this will have on the Core for delete
.
Why would this increase the size of the unfolding?
My bad. Briefly, I had thought that the unfolding for delete
would contain the unoptimized unfolding of alter
.
I can't really tell if the benchmarks get faster or not, which is a bit weird.
I wonder if the old alter
inlines, thus removing the closure and simplifying the cases. I am pretty sure the new alter
will never inline.
Resolves #404