Skip to content

scpmw/haskell-concatMapWrite

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

I'm trying to do reasonably fast character escaping in Haskell (that is, within a few factors of C). Using plain ByteString manipulation, my Haskell implementation is 125 times slower than my C implementation. Then I tried to use blaze-builder. That was even slower.

I eventually managed to get it to about 1.5 times slower than the C version (very good!). The key function is this:

concatMapWrite :: (Word8 -> Write) -> ByteString -> ByteString

It is like concatMap from Data.ByteString. However, instead of the callback returning a ByteString, it returns a Write which is used to write the data directly into a buffer.

However, there are two problems:

  • It uses a lot of ugly buffer manipulation,

  • The performance boost is very sensitive to what gets inlined and what doesn't.

Is there a better way to translate a sequence of bytes in Haskell than this?

About

Fast character escaping in Haskell

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Haskell 64.2%
  • C 35.8%