Fast parsing of unboxed values without boxing them in the parser?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Fast parsing of unboxed values without boxing them in the parser?

Eugene Kirpichov
Hi cafe,

Are there any libraries that can be used for very fast parsing of
binary data into structures with unboxed fields?
The "naive" way, as implemented in Data.Binary etc, has the parsing
monad datatype (say, "Get a") be parametric in "a" and include a field
of type "a", which makes it impossible for a parser to return an
unboxed value (e.g. parse a word32 from a byte array).

I'm thinking that a CPS-style parser type could allow returning an
unboxed value as a result of the compiler inlining and fusing together
the parsing code and the code that consumes the parsed value.

Are there any libraries that work like this?

--
Eugene Kirpichov
http://www.linkedin.com/in/eugenekirpichov
We're hiring! http://tinyurl.com/mirantis-openstack-engineer

_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Fast parsing of unboxed values without boxing them in the parser?

Bryan O'Sullivan
On Tue, Oct 23, 2012 at 3:26 AM, Eugene Kirpichov <[hidden email]> wrote:
I'm thinking that a CPS-style parser type could allow returning an
unboxed value as a result of the compiler inlining and fusing together
the parsing code and the code that consumes the parsed value.

Are there any libraries that work like this?

Both cereal (for binary) and attoparsec (text) are written in a CPS style that can support this in principle. For parsers of even modest complexity, GHC won't necessarily succeed at unboxing values, though; you have to inspect the Core to see if what's going on matches what you're hoping for.

_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe