ocaml / merlin

Context sensitive completion for OCaml in Vim and Emacs
https://ocaml.github.io/merlin/
MIT License
1.58k stars 233 forks source link

Locate performance regression for v4.5-414 #1468

Open Zineb-Ada opened 2 years ago

Zineb-Ada commented 2 years ago

We ran this command line ocamlmerlin single locate -look-for ml -position 171:13 -filename src/irmin-pack/mem/irmin_pack_mem.ml < src/irmin-pack/mem/irmin_pack_mem.ml | jq. and we noticed a performance regression between the old and the new version of Merlin. As you can see below, oddly the “cpu” of version v4.4-413 is faster than that of v4.5-414. We can see that this lag is especially due to the “query” field which has increased significantly.

Ocaml=4.14.0; Merlin= v4.5-414

{
  "class": "return",
  "value": {
    "file": "/Users/tarides/Desktop/Tarides-Ocaml/irmin/src/irmin/irmin.ml",
    "pos": {
      "line": 1,
      "col": 0
    }
  },
  "notifications": [],
  "timing": {
    "clock": 600,
    "cpu": 426,
    "query": 234,
    "pp": 0,
    "reader": 2,
    "ppx": 31,
    "typer": 160,
    "error": 0
  }
}

Ocaml=4.13.1 Merlin= v4.4-413

{
  "class": "return",
  "value": {
    "file": "/Users/tarides/Desktop/Tarides-Ocaml/irmin/src/irmin/irmin.ml",
    "pos": {
      "line": 1,
      "col": 0
    }
  },
  "notifications": [],
  "timing": {
    "clock": 189,
    "cpu": 166,
    "query": 32,
    "pp": 0,
    "reader": 4,
    "ppx": 15,
    "typer": 114,
    "error": 0
  }
}
Zineb-Ada commented 2 years ago

Here is an another example of performance regression between ocaml 4.14.0 and 4.12.1 with the same command ocamlmerlin single locate -look-for ml -position 20:16 -filename ./examples/trees.ml < ./examples/trees .ml| jq . on the same repository. The CPU difference, as you can see below, is very high. when we do the command "Go To The Definition" on Irmin_unix on line : 20;

module Store = Irmin_unix.Git.FS.KV (Irmin.Contents.String)

Ocaml=4.14.0

{
  "class": "return",
  "value": {
    "file": "/Users/tarides/Desktop/Tarides-Ocaml/irmin/src/irmin-unix/irmin_unix.ml",
    "pos": {
      "line": 1,
      "col": 0
    }
  },
  "notifications": [],
  "timing": {
    "clock": 1370,
    "cpu": 1355,
    "query": 1149,
    "pp": 0,
    "reader": 1,
    "ppx": 22,
    "typer": 183,
    "error": 0
  }
} 

ocaml 4.12.1

{
  "class": "return",
  "value": {
    "file": "/Users/tarides/Desktop/Tarides-Ocaml/irmin/src/irmin-unix/irmin_unix.ml",
    "pos": {
      "line": 1,
      "col": 0
    }
  },
  "notifications": [],
  "timing": {
    "clock": 441,
    "cpu": 321,
    "query": 73,
    "pp": 0,
    "reader": 1,
    "ppx": 25,
    "typer": 223,
    "error": 0
  }
}
art-w commented 2 years ago

In case it helps to identify the issue, on the offending line reported by @Zineb-Ada , it gets faster when locating the submodules:

module Store = Irmin_unix.  Git.  FS.  KV   (...)
(*             ^            ^     ^    ^
locate (ms)    |            |     |    |
4.13.1 :       55           80    80   80   --> increasing
4.14.0 :     1368         1156   741  534   --> decreasing (?!)
*)