runtime fusion for Data.ByteString.cons ?

Claus Reinke claus.reinke at talk21.com
Sun Nov 19 18:32:19 EST 2006


[just saw your reply while sending this, so perhaps there's nothing new here?
 but then why the runtime difference? anyway, here goes nothing :-]

> a tentative idea would be to overload create so that it produces a proper,
> allocated ByteString where such is expected, but can also just pass through
> the PreBS where the context can handle it?

attached is a variant that seems to do the trick, although I do confess myself
slightly surprised that it does (I had thought that simplifier rules would be too
late to fix overloaded types..).

the core code for mapBS and mapBS' is now the same, but the versions of
empty and cons used in the latter can produce either variant of ByteString,
unallocated pre-ByteStrings or allocated ByteStrings (the instances of 
class IsByteString), and cons can also handle both variants as second
parameter. 

so all we do in the simplifier rule is to request that mapBS' should internally
use unallocated pre-ByteStrings, converting to allocated ByteString only at
the end (this request then forces empty and cons to produce pre-ByteStrings
as well, switching the whole recursion over to that representation). as I said, 
I'm somewhat surprised that this works, but commenting out the rule does 
have the expected impact on performance..

what do you think?
Claus
-------------- next part --------------
A non-text attachment was scrubbed...
Name: BScons.hs
Type: application/octet-stream
Size: 2525 bytes
Desc: not available
Url : http://www.haskell.org/pipermail/glasgow-haskell-users/attachments/20061119/a5dec06d/BScons.obj


More information about the Glasgow-haskell-users mailing list