Skip to content

How Parseff compares to Angstrom in performance, API style, and trade-offs.

Angstrom is the most widely used parser combinator library in the OCaml ecosystem. This page compares Parseff and Angstrom side by side: performance, API style, and when to use each.

Benchmarked on a JSON array parser ({[1, 2, 3, ..., 10]}) over 100,000 iterations. Sources: bench/bench_json.ml, bench/bench_vs_angstrom.ml.

Parses/sec vs. Angstrom Minor allocs
Parseff (zero-copy) ~5,270,000 4.8x faster 168 MB
Parseff (fair) ~1,930,000 1.8x faster 184 MB
MParser ~1,330,000 1.2x faster 466 MB
Angstrom ~1,090,000 baseline 584 MB

Zero-copy uses sep_by_take_span with a custom float_of_span that avoids float_of_string. This represents the fastest path when you control the conversion logic.

Fair uses the same float_of_string call as MParser and Angstrom, isolating parsing overhead from number conversion.

All parsers produce the same output (float list) from the same input.

Direct character scanning. Parseff.take_while runs a tight while loop with character predicates. No regex compilation, no automaton overhead.

Fewer allocations. Span-based APIs return { buf; off; len } slices of the input string without calling String.sub. Angstrom’s take_while1 allocates a new string per call.

Fused operations. Parseff.sep_by_take_span parses an entire separated list in a single effect dispatch. Angstrom’s equivalent chains sep_by, char, skip_while, and take_while1 through monadic operators, each creating closures.

No monadic overhead. Parsers are direct function calls. No CPS, no closure allocation for sequencing.

The fundamental difference: Parseff uses direct-style imperative code. Angstrom uses monadic composition.

Parseff:

let key_value () =
let key = Parseff.take_while1 (fun c -> c <> ':') ~label:"key" in
let _ = Parseff.char ':' in
Parseff.skip_whitespace ();
let value = Parseff.take_while1 (fun c -> c <> '\n') ~label:"value" in
(key, value)

Angstrom:

let key_value =
take_while1 (fun c -> c <> ':') >>= fun key ->
char ':' >>= fun _ ->
skip_while is_ws >>= fun () ->
take_while1 (fun c -> c <> '\n') >>= fun value ->
return (key, value)

Both do the same thing. Parseff reads like sequential OCaml code. Angstrom threads results through >>= and return.

Parseff:

let value () =
Parseff.one_of
[ null_parser; bool_parser; number_parser; string_parser ]
()

Angstrom:

let value =
null_parser <|> bool_parser <|> number_parser <|> string_parser

Similar readability. Angstrom’s <|> is more concise. Parseff’s Parseff.one_of is explicit about the list structure.

Parseff:

let numbers () =
Parseff.sep_by
(fun () ->
Parseff.skip_whitespace ();
let s = Parseff.take_while1 is_digit ~label:"digit" in
Parseff.skip_whitespace ();
int_of_string s)
(fun () -> Parseff.char ',')
()

Angstrom:

let numbers =
sep_by (ws *> char ',' <* ws)
(take_while1 is_digit >>| int_of_string)

Angstrom is more concise here thanks to applicative operators (*>, <*). Parseff is more explicit: whitespace handling is visible, not hidden in operator chains.

Here’s the same expression parser in both libraries:

Parseff:

let rec expr () =
Parseff.chainl1
term
(fun () ->
Parseff.skip_whitespace ();
let _ = Parseff.char '+' in
Parseff.skip_whitespace ();
fun a b -> a + b)
()
and term () =
Parseff.chainl1
factor
(fun () ->
Parseff.skip_whitespace ();
let _ = Parseff.char '*' in
Parseff.skip_whitespace ();
fun a b -> a * b)
()
and factor () =
Parseff.or_
(fun () ->
let _ = Parseff.char '(' in
let e = expr () in
let _ = Parseff.char ')' in
e)
(fun () -> Parseff.digit ())
()

Angstrom:

let expr =
fix (fun expr ->
let factor =
char '(' *> expr <* char ')'
<|> (satisfy is_digit >>| fun c -> Char.code c - 48)
in
let term =
chainl1 factor (ws *> char '*' <* ws >>| fun _ -> ( * ))
in
chainl1 term (ws *> char '+' <* ws >>| fun _ -> ( + ))
)

Angstrom is denser. Parseff is more readable for people who aren’t fluent in monadic/applicative operators.

FeatureParseffAngstrom
OCaml version5.3+4.x+
API styleImperative (direct effects)Monadic (CPS-based)
Streamingparse_source with Source.tBuffered / Unbuffered modules
BacktrackingAutomatic via or_Automatic via `<
Zero-copyspan type + fused opsNot built-in
Recursion safetyrec_ with ~max_depthManual (no built-in depth limit)
Custom errorserror with polymorphic variantsLimited (string-based)
Error labelsexpect, one_of_labeled<?> operator
Async supportNot built-in (wrap in Domain)Incremental API with Partial
MaturityNewBattle-tested, widely used
FeatureParseffAngstromMParserOpal
Imperative-style APIYesNoNoNo
Monadic interfaceNoYesYesYes
Backtracking by defaultYesYesNoNo
Unbounded lookaheadYesYesYesNo
Custom error typesYesNoNoNo
Zero-copy APIYesYesNoNo
Streaming/incrementalYesYesNoNo
Requires OCaml 5+YesNoNoNo
Note: MParser and Opal require explicit backtracking (like Parsec’s try). Angstrom and Parseff backtrack automatically on alternation. MParser and Opal don’t support streaming input. Only Parseff supports custom typed errors beyond strings.