Closed effectfully closed 5 years ago
@mchakravarty is this pertinent given the use of Unique
s?
Is there any evidence of the above issues occurring when performing profiling or benchmarking?
is this pertinent given the use of
Unique
s?
How are uniques related?
Is there any evidence of the above issues occurring when performing profiling or benchmarking?
I've been wanting to switch to unpinned for ByteString for years, but it's a lot of work. It'd mean fixing up lots of other libs that use ByteString internals and it also requires a solution for the mmap'd ByteString use case (which does have solutions but it's still more work and may need some RTS extensions to be able to have an mmaped ByteArray# that unmaps when it's collected).
As a workaround I often recommend people use ShortByteString, which is part of the bytestring package and uses unpinned memory.
Text
which would also save us some pain related to handling of variable names, like this for example:language-plutus-core/generators/Language/PlutusCore/Generators/Internal/Entity.hs:import Data.Text.Encoding (encodeUtf8)
language-plutus-core/generators/Language/PlutusCore/Generators/Internal/Entity.hs: Name ann (name <> BSL.fromStrict (encodeUtf8 . prettyText $ unUnique uniq)) uniq
language-plutus-core/src/Language/PlutusCore/Quote.hs:freshNameText ann = freshName ann . BSL.fromStrict . Text.encodeUtf8
A
Text
value uses unpinned memory - meaning that it is controlled by the GHC garbage collector and can be moved around at will. -- string-types
So we can go with just strict Text
for now and try ShortText
later in a benchmark-driven way if we have time for that.
A Text value uses unpinned memory - meaning that it is controlled by the GHC garbage collector and can be moved around at will. -- string-types
That's not relevant in our case.
That's not relevant in our case.
Why not? Pinned memory is leaky, unpinned memory is not. Seems relevant to me.
The docs state:
so we shouldn't use lazy
ByteString
s for variables names, because names are small.Moreover, we probably shouldn't use any pinned-memory-based data structures for name handling, because they cause memory fragmentation when there are many of them and we don't want to analyze whether we have "many" names or not, because it's error-prone.
Our best bet is probably
ShortText
(which is defined in terms ofShortByteString
which is not pinned-memory-based). Related blog post.