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

High CPU Usage when parsing fails? #114

Closed
antew opened this issue Jul 21, 2019 · 10 comments
Closed

High CPU Usage when parsing fails? #114

antew opened this issue Jul 21, 2019 · 10 comments
Labels
bug Something isn't working

Comments

@antew
Copy link
Member

antew commented Jul 21, 2019

This was reported on Slack and I think I found one way to reproduce it reliably, if anyone else can try it out it would be good to have confirmation!

Steps to Reproduce

  1. git clone https://github.com/rtfeldman/elm-spa-example
  2. Open the project in an editor with the language server enabled.
  3. Open src/Main.elm
  4. Give it a second for the warnings to show up
  5. Delete from line 1 to line 35 (this block below)
module Main exposing (main)

import Api exposing (Cred)
import Article.Slug exposing (Slug)
import Avatar exposing (Avatar)
import Browser exposing (Document)
import Browser.Navigation as Nav
import Html exposing (..)
import Json.Decode as Decode exposing (Value)
import Page exposing (Page)
import Page.Article as Article
import Page.Article.Editor as Editor
import Page.Blank as Blank
import Page.Home as Home
import Page.Login as Login
import Page.NotFound as NotFound
import Page.Profile as Profile
import Page.Register as Register
import Page.Settings as Settings
import Route exposing (Route)
import Session exposing (Session)
import Task
import Time
import Url exposing (Url)
import Username exposing (Username)
import Viewer exposing (Viewer)



-- NOTE: Based on discussions around how asset management features
-- like code splitting and lazy loading have been shaping up, it's possible
-- that most of this file may become unnecessary in a future release of Elm.
-- Avoid putting things in this module unless there is no alternative!
-- See https://discourse.elm-lang.org/t/elm-spa-in-0-19/1800/2 for more.
  1. CPU usage will spike to 99% and stay there, even if you undo the changes, it seems like you have to kill and restart the language server.

From taking a profile while this is happening it looks like this is the callstack, it gets stuck somewhere in trying to find a function.
image

@razzeee
Copy link
Member

razzeee commented Jul 22, 2019

I can't seem to really get the parser stuck, running a copy of that file. Copied to https://github.com/Razzeee/tree-sitter-elm/blob/master/examples/test.elm and running https://github.com/Razzeee/tree-sitter-elm/blob/master/package.json#L26

But I found the two errors I mentioned here. (one is inside a comment)
Not sure they are connected at all.
tree-sitter/tree-sitter#394

@razzeee razzeee added the bug Something isn't working label Jul 22, 2019
@razzeee
Copy link
Member

razzeee commented Jul 24, 2019

It doesn't seem to matter what I change, even if I remove just the comment it happens.

Even if I remove some type constructor or a type annotation

@andys8
Copy link
Member

andys8 commented Jul 25, 2019

Is it reasonable to consider a hotfix that'll timeout findfunction, cancel and recover? Would it even be possible?

@razzeee
Copy link
Member

razzeee commented Jul 25, 2019

While I'm able to get the 100% cpu useage, I can't get a callstack that's similar or point's at findFunction. It even keeps happening, when I empty out findFunction.

Seems like we might need to revert to the old way of supplying tree-sitter.

@razzeee
Copy link
Member

razzeee commented Jul 29, 2019

Not sure it really is findFunction, it seems to start for me when we pass https://github.com/elm-tooling/elm-language-server/blob/master/src/forest.ts#L81
Or does not happen at all, when I comment it out. Still, I have no idea how that could trigger it.

The new tree should already be parsed at that point, so in theory it can't be the wasm update/the parser.

@razzeee
Copy link
Member

razzeee commented Jul 30, 2019

@razzeee
Copy link
Member

razzeee commented Jul 31, 2019

If you can, please test with master. I will very likely prepare a release very soon.

@antew
Copy link
Member Author

antew commented Aug 1, 2019

Tested on latest master and the issue no longer happens for me :-)

@andys8
Copy link
Member

andys8 commented Aug 1, 2019

Wow, that's great news. Will try it.

@ymtszw
Copy link

ymtszw commented Aug 2, 2019

Re-enabled for a whole work way, and it works smooth! (VSCode 1.36.1)
Deeply appreciated ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants