Fail-early when overflow of `Check_size` in `Binary_length`
The following discussion from !75 (merged) should be addressed:
-
@archaephyrryx started a discussion: (+2 comments) This feels a bit inefficient, even if it isn't a common case to optimize for:
Is it worth considering a short-circuiting computation that terminates any further recursion or iteration once a certain check-limit has been exceeded?
There are numerous potential approaches to this, some of which might stunt the performance of other cases, so it is difficult to tell how much overhead is justified.
The cleanest but potentially most expensive way would be to add an optional parameter
?max_len
tolength
, that is propagated into recursive calls, and which is used as a short-circuit condition before anything is evaluated, so that the update-function inList.fold_left
calls raises the appropriate exception with the recursive call tolength
itself, with the limit parameter. This would additionally require the accumulated length to be an explicit parameter, rather than a term in a summation.