-
Notifications
You must be signed in to change notification settings - Fork 141
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
Uncons should not produce thunks #558
Labels
blocked: ghc
This is blocked on a feature or primitive not yet available in a released GHC version
performance
Comments
clyring
added
blocked: ghc
This is blocked on a feature or primitive not yet available in a released GHC version
performance
labels
Nov 23, 2022
clyring
added a commit
to clyring/bytestring
that referenced
this issue
Nov 23, 2022
...at least for the second component of its result. The thunk for the first component is a bit hairier because the readWord8OffAddr# is considered a side effect by GHC and hence can currently never go away unless it is used lazily. See also haskell#558.
clyring
added a commit
that referenced
this issue
Nov 25, 2022
...at least for the second component of its result. The thunk for the first component is a bit hairier because the readWord8OffAddr# is considered a side effect by GHC and hence can currently never go away unless it is used lazily. See also #558.
The problem with the second component of |
Bodigrim
pushed a commit
to Bodigrim/bytestring
that referenced
this issue
Nov 26, 2022
...at least for the second component of its result. The thunk for the first component is a bit hairier because the readWord8OffAddr# is considered a side effect by GHC and hence can currently never go away unless it is used lazily. See also haskell#558.
vdukhovni
pushed a commit
to vdukhovni/bytestring
that referenced
this issue
Dec 7, 2022
...at least for the second component of its result. The thunk for the first component is a bit hairier because the readWord8OffAddr# is considered a side effect by GHC and hence can currently never go away unless it is used lazily. See also haskell#558.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
blocked: ghc
This is blocked on a feature or primitive not yet available in a released GHC version
performance
Consider
Lazy.uncons
. Today, we have inData.ByteString.Lazy
:Both components of the returned tuple internally perform a small amount of work before constructing a result:
I#
result. Since the compiler doesn't know that this read should not fail, it cannot perform the read eagerly; it must create a thunk. (TheStrictByteString
version ofuncons
has the same issue here.)cs
or allocating a newChunk
object. This is just an comparison between evaluatedInt
s, and certainly succeeds in little time, so a compiler would be well within its rights to eagerly compareS.length c
with1
, but GHC today does not do so for what-ever reason.What should we do about this?
uncons
strict inS.unsafeHead c
, but then the resultingreadWord8OffAddr#
read-effect operations will stick around even if the result is un-used, which is a bit unfortunate. (Maybe Cmm assignment sinking or the register allocator can clean it up very late in the pipeline. I haven't checked.) And users pattern-matching on the result ofuncons
have an easy work-around: Use a bang-pattern themselves. So I'm not convinced this behavior should be changed before GHC starts to discard unused read-effects in its simplifier.S.length
check eagerly: Since the thunk that would be allocated is one word larger than theChunk
cell allocated in the else branch, I expect eagerly performing this comparison to be cheaper on average even if the thunk would never be evaluated. And users pattern-matching on the result ofuncons
have no comfortable workaround, since a bang-pattern may force the lazy tail prematurely. I will put up a merge request implementing this momentarily.The text was updated successfully, but these errors were encountered: