markup.ml
markup.ml copied to clipboard
Slow `lookup` function in `utility.ml`
Hi, I was randomly reading your code, and found this line: https://github.com/aantron/markup.ml/blob/d686cce6bac6ff46a49b28ed0d957ffa1e37fda5/src/utility.ml#L448
let rec lookup index =
if index >= Array.length Entities.entities then raise Exit
else
if fst Entities.entities.(index) <> name then lookup (index + 1)
else snd Entities.entities.(index)
in
Here, the function lookup searches the index of a name in the HTML entities, which is quite large. The search is done linearly through the entire array Entities.entities. Wouldn't it be worth using an ocaml map here to speed-up the search?
Yes, potentially, perhaps even likely, but I'd rather know first that it is an actual bottleneck, empirically. Perhaps on a pathological example.