markup.ml icon indicating copy to clipboard operation
markup.ml copied to clipboard

Slow `lookup` function in `utility.ml`

Open Mbodin opened this issue 5 months ago • 1 comments

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?

Mbodin avatar Jul 24 '25 09:07 Mbodin

Yes, potentially, perhaps even likely, but I'd rather know first that it is an actual bottleneck, empirically. Perhaps on a pathological example.

aantron avatar Aug 09 '25 06:08 aantron