Skip to content

CPU usage with vscode and the petrol library #1489

Closed
ocaml/merlin
#1944

Description

@clecat

Hello,

I am currently working with the library petrol while coding in vscode and I have encountered a strange issue with ocamllsp: Indeed, whenever I try to code SQL queries using Petrol's Query and Expr modules, my whole editor seems to slow down quite substantially and code correction stops working altogether.

When I check my processes, it appears that the ocamllsp process has a CPU usage of 100%. The only "workaround" is found is to kill the process and use the short time window where everything works fine before it starts again.

I figured I should open this issue as you might have better solutions,
Thank you for your time, Gwen

Activity

  1. voodoos commented on Feb 27, 2025

    @voodoos
    Collaborator

    Thanks to Gwen's guidance I was able to reproduce the issue consistently. It is to the codeActions request that enters a seamingly infinite loop.

    There is workaround in vscode: disable the display of the code action lightbulb 💡

    Image
  2. qexat commented on Jun 11, 2025

    @qexat

    I stumbled upon an issue that seems to be of the same origin, so I crafted a minimal piece of code that triggers the bug:

    type 'item list =
      | []
      | ( :: ) of ('item * 'item list)
    
    module List = struct
      type 'item t = 'item list
    
      (* start typing some new definition here, for example reverse_concat *)
    end

    Specs

    EndeavourOS Linux 6.14.10-arch1-1
    OCaml v5.3.0
    ocamllsp v1.22.0
    Visual Studio Code v1.100.3 (258e40fedc6cb8edf399a463ce3a9d32e7e1f6f3)

  3. voodoos commented on Jun 12, 2025

    @voodoos
    Collaborator

    Thanks a lot @qexat, this is a surprisingly minimal example !

    So far I have not been able to reproduce, I must be missing some context. Could you share the dune file and other relevant configuration information ? Or better, an archive with a minimum project ?

  4. qexat commented on Jun 12, 2025

    @qexat

    Huh, weird, my folder repro is literally just a file Repro.ml containing the code I have sent

    Have you started typing a new definition? The code as is does not trigger it

  5. voodoos commented on Jun 13, 2025

    @voodoos
    Collaborator

    Huh, weird, my folder repro is literally just a file Repro.ml containing the code I have sent

    Have you started typing a new definition? The code as is does not trigger it

    I am not able to produce a stuck 100% cpu usage ocamllsp in the way you describe.

    Could you enable verbose logging in the settings ? ocaml.trace.server is the name of the setting.
    Then could you reload the window, bring it to the buggy state and share with us the content of the OCaml Language Server section in the OUTPUT panel ?

  6. qexat commented on Jun 13, 2025

    @qexat

    Okay, I figured the issue with my reproduction sample. The new definition needs to involve pattern matching specifically.

    [Trace - 5:50:37 PM] Received response 'textDocument/foldingRange - (175)' in 1779ms. Request failed: cancelled (-32800).
    [Trace - 5:50:38 PM] Received response 'textDocument/codeLens - (184)' in 1612ms.
    Result: []
    
    
    [Trace - 5:50:38 PM] Received response 'textDocument/documentSymbol - (178)' in 2686ms. Request failed: cancelled (-32800).
    [Trace - 5:50:38 PM] Received response 'textDocument/signatureHelp - (174)' in 2920ms. Request failed: cancelled (-32800).
    [Trace - 5:50:38 PM] Received response 'textDocument/documentSymbol - (177)' in 2688ms. Request failed: cancelled (-32800).
    [Trace - 5:50:38 PM] Received response 'textDocument/inlayHint - (181)' in 1820ms. Request failed: cancelled (-32800).
    [Trace - 5:50:50 PM] Sending notification '$/cancelRequest'.
    Params: {
        "id": 180
    }
    
    
    [Trace - 5:50:50 PM] Sending notification '$/cancelRequest'.
    Params: {
        "id": 182
    }
    
    
    [Trace - 5:50:50 PM] Received response 'textDocument/completion - (180)' in 14146ms. Request failed: cancelled (-32800).
    [Trace - 5:50:50 PM] Received response 'textDocument/signatureHelp - (182)' in 14094ms. Request failed: cancelled (-32800).
    
  7. voodoos commented on Jun 24, 2025

    @voodoos
    Collaborator

    Thanks, I was able to reproduce and make the example even more minimal:

    type t = ( :: )
    
    let f (x: t) =  x
    

    Placing the cursor on x here make the server loop. 🤦‍♂️

  8. added a commit that references this issue on Jun 24, 2025
    8fba5c3
  9. added a commit that references this issue on Jun 24, 2025
    b1e7955
  10. qexat commented on Jun 24, 2025

    @qexat

    Nice, thank you!

  11. added a commit that references this issue on Aug 19, 2025
    24d9c13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions