You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Optimize encodeUtf8 by checking if the byte array is already pinned #471
A byte array [and by extension Text] can be pinned as a result of three possible causes:
It was allocated by newPinnedByteArray#. [Text is never constructed using this primitive]
It is large. Currently, GHC defines large object to be one that is at least as large as 80% of a 4KB block (i.e. at least 3277 bytes).
It has been copied into a compact region. The documentation for ghc-compact and compact describes this process.
Especially 2 seems likely and a case where we could save a significant amount of time by avoiding copying. Could we use isByteArrayPinned# to check if the byte array is already pinned and in that case avoid copying?
Ah, I didn't think about slicing. I guess it is best to only reuse the original byte array if it is both pinned and not sliced. Although perhaps it would be acceptable to reuse the original byte array if the slice is still like 90% of the original size, but I don't think that is particularly common.
Activity
Bodigrim commentedon Sep 29, 2022
text/src/Data/Text/Encoding.hs
Lines 528 to 538 in 5558730
Might be worth a try, but take care not to retain the original pinned
ByteArrayifTexthas been sliced.noughtmare commentedon Sep 30, 2022
Ah, I didn't think about slicing. I guess it is best to only reuse the original byte array if it is both pinned and not sliced. Although perhaps it would be acceptable to reuse the original byte array if the slice is still like 90% of the original size, but I don't think that is particularly common.