Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specify -index 0 in type-enclosing queries. #1191

Merged
merged 3 commits into from
Sep 26, 2023

Conversation

voodoos
Copy link
Collaborator

@voodoos voodoos commented Sep 26, 2023

This change greatly improves performances in some cases where Merlin would spend a lot of time formatting big types that were discarded by ocaml-lsp anyway.

This fixes type-enclosing taking 10s in Irmin:

❯ ocamlmerlin single type-enclosing -position 146:39 -filename src/irmin-pack/mem/irmin_pack_mem.ml <src/irmin-pack/mem/irmin_pack_mem.ml | jq '.timing'
{
  "clock": 11399,
  "cpu": 11321,
  "query": 11153,
  "pp": 0,
  "reader": 1,
  "ppx": 23,
  "typer": 144,
  "error": 0
}
❯ ocamlmerlin single type-enclosing -position 146:39 -filename src/irmin-pack/mem/irmin_pack_mem.ml -index 0 <src/irmin-pack/mem/irmin_pack_mem.ml | jq '.timing'
{
  "clock": 238,
  "cpu": 183,
  "query": 17,
  "pp": 0,
  "reader": 1,
  "ppx": 22,
  "typer": 142,
  "error": 0
}

This does not fix every issue on Irmin's codebase: hovering on some modules causes ocaml-lsp to hang at 100% cpu.
This happens for example with this query, which is instantaneous in Merlin:

❯ ocamlmerlin single type-enclosing -position 43:40 -index 0 -filename src/irmin-pack/mem/irmin_pack_mem.ml <src/irmin-pack/mem/irmin_pack_mem.ml | jq '.timing'
{
  "clock": 263,
  "cpu": 207,
  "query": 40,
  "pp": 0,
  "reader": 1,
  "ppx": 23,
  "typer": 144,
  "error": 0
}

Cancellation is not working and the process must be manually killed.

I will open an issue for this, it is independent from the problem solved by that PR that should increase performance without drawbacks in many cases.

This change might greatly improve performances in some cases where Merlin would format big types that were discarded by ocaml-lsp anyway.
@rgrinberg
Copy link
Member

rgrinberg commented Sep 26, 2023

formatting big types that were discarded by ocaml-lsp anyway.

Formatting as in pretty printing? I'm curious how this can be so slow.

By the way, is it possible to add a test that demonstrates there's a change in behavior?

@voodoos
Copy link
Collaborator Author

voodoos commented Sep 26, 2023

Formatting as in pretty printing? I'm curious how this can be so slow.

I agree that this is surprising, Merlin's relies on Printtyp to pretty print.

By the way, is it possible to add a test that demonstrates there's a change in behavior?

There is no change in behavior since ocaml-lsp only uses the first result in the list:

https://github.com/ocaml/ocaml-lsp/blob/master/ocaml-lsp-server/src/document.ml#L306-L311

image

@rgrinberg rgrinberg merged commit c6cc715 into ocaml:master Sep 26, 2023
9 checks passed
@rgrinberg rgrinberg added this to the 1.17.0 milestone Sep 26, 2023
voodoos added a commit to voodoos/opam-repository that referenced this pull request Dec 18, 2023
CHANGES:

## Fixes

- Fix missing super & subscripts in markdown documentation. (ocaml/ocaml-lsp#1170)

- Do not invoke dune at all if `--fallback-read-dot-merlin` flag is on. (ocaml/ocaml-lsp#1173)

- Fix semantic highlighting of infix operators that contain '.'. (ocaml/ocaml-lsp#1186)

- Disable highlighting unit as an enum member to fix comment highlighting bug. (ocaml/ocaml-lsp#1185)

- Improve type-on-hover and type-annotate efficiency by only formatting the type
  of the first enclosing. (ocaml/ocaml-lsp#1191, ocaml/ocaml-lsp#1196)

- Fix the encoding of URI's to match how vscode does it (ocaml/ocaml-lsp#1197)

- Fix parsing of completion prefixes (ocaml/ocaml-lsp#1181)

## Features

- Compatibility with Odoc 2.3.0, with support for the introduced syntax: tables,
  and "codeblock output" (ocaml/ocaml-lsp#1184)

- Display text of references in doc strings (ocaml/ocaml-lsp#1166)

- Add mark/remove unused actions for open, types, for loop indexes, modules,
  match cases, rec, and constructors (ocaml/ocaml-lsp#1141)

- Offer auto-completion for the keyword `in` (ocaml/ocaml-lsp#1217)
nberth pushed a commit to nberth/opam-repository that referenced this pull request Jun 18, 2024
CHANGES:

## Fixes

- Fix missing super & subscripts in markdown documentation. (ocaml/ocaml-lsp#1170)

- Do not invoke dune at all if `--fallback-read-dot-merlin` flag is on. (ocaml/ocaml-lsp#1173)

- Fix semantic highlighting of infix operators that contain '.'. (ocaml/ocaml-lsp#1186)

- Disable highlighting unit as an enum member to fix comment highlighting bug. (ocaml/ocaml-lsp#1185)

- Improve type-on-hover and type-annotate efficiency by only formatting the type
  of the first enclosing. (ocaml/ocaml-lsp#1191, ocaml/ocaml-lsp#1196)

- Fix the encoding of URI's to match how vscode does it (ocaml/ocaml-lsp#1197)

- Fix parsing of completion prefixes (ocaml/ocaml-lsp#1181)

## Features

- Compatibility with Odoc 2.3.0, with support for the introduced syntax: tables,
  and "codeblock output" (ocaml/ocaml-lsp#1184)

- Display text of references in doc strings (ocaml/ocaml-lsp#1166)

- Add mark/remove unused actions for open, types, for loop indexes, modules,
  match cases, rec, and constructors (ocaml/ocaml-lsp#1141)

- Offer auto-completion for the keyword `in` (ocaml/ocaml-lsp#1217)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants