-
-
Notifications
You must be signed in to change notification settings - Fork 28
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
LTeX gets stuck in an almost infinite loop in very long documents #253
Comments
The docs for From the description of the problem, it sounds like it's like you say: Each keystroke causes LTEX to run one check, and these checks stack up. I experienced the same problem when I experimented with having Pandoc as a Markdown backend (which might cost ~1s per conversion; LTEX checks will take a lot longer if In the meantime, as a workaround, either increase The reason why |
Just to clarify, I think the issue might be the requests which don't get cancelled. The large document etc, are contextual, and rather descriptive of the context in which I noticed that requests seem to get queued up. I.e.:
Which makes it possible to stack up a lot of spellcheck requests. I noticed that something was fishy not because of CPU-usage (my workstation is a bit over the top for latex) but because the spellcheck came back "wrong" which could be seen since the wrong words and passages were marked in the text (due to positions etc being of since the text had been modified since the request for spellcheck was sent). I.e., I believe, without fully going into all the logs, that the spellchecker backend might have been working on, lets say, request 43 while the front-end vscode-ltex just sent request 163 or so. Which indicates that older requests don't get cancelled asynchronously, which the logs indicate that they should be. If they were cancelled correctly, I believe that I would not have seen such horrendous results for multiple large files. |
The cancellation requests are not handled correctly because LTEX checks synchronously. Making the check process asynchronous would of course be another option, but that's probably quite hard as most of the existing code is not thread-safe. |
I think I'm going to have a look, since this annoys me :-) Can you move this issue to LTeX, or should I close this one and open a new one at LTeX? |
You mean ltex-ls (LTEX is usually vscode-ltex + ltex-ls). There's not really a strict separation in terms of issues (many issues affect both vscode-ltex and ltex-ls). But in this case, we can keep this issue here for visibility. I've come to the conclusion that you have to have asynchronous checks, otherwise there's no way to cancel them. I implemented a basic version for this on a new branch of ltex-ls, but sometimes the program waits if a check is currently running in the checking thread, before handing the edit event over to ltex-ls and giving us the chance to cancel it. I'm a bit stuck right now. |
Same problem here: impossible to use LTeX for longer documents. |
This issue is already confirmed. Please upvote the issue using the thumbs-up reaction to help reduce noise. Thank you! |
After greatly improving debugging facilities, I was able to see the problem of my branch code. It seems Java somehow reuses threads if they are currently waiting. If I understand it correctly, the RPC thread waited for the checking thread to return a result, but the Some testing still needs to be done as I'm not yet entirely sure everything is working as intended. @flindeberg I'm not sure about your “expected behavior” section. The implemented solution tries to cancel the checking process if a new edit is sent to the server. Then, the updated text (after the edit) is checked. If there are multiple edits, then they don't stack anymore; only the last edit is checked. However, the root problem is that the sentence cache is too small (if it wasn't too small, checking would only take milliseconds). This means the checking of the updated text will take as long as the initial checking, minus the time for the cached sentences. For example, if you have a document of 20000 sentences, but your sentence cache only has size 2000, and every sentence takes 0.01s, then the initial checking will take 200s, but the subsequent checks will also take 180s, so almost the same (as 18000 sentences have to be checked). There is no way that these subsequent checks only take “a couple of seconds” as you write, especially if you exceed the size of the sentence cache by a lot as in my example. This issue is just about the almost infinite loop due to the stacking of the checks. If you want fast checking, you cannot get around increasing the sentence cache size. Maybe it's possible to detect LTEX takes a lot of time, and offer to increase (e.g., double) the sentence cache size. |
Fix released in 10.2.0. |
This seems to work now. |
First of all, a huge thank you @valentjn for providing this very helpful plugin! It boosts writing my PhD thesis ❤️ I ran into this issue with the current version of vscode-ltex (13.0.0) and ltex-ls (15.0.0) & jdk (11.0.12+7) auto-installed by the extension. My document currently contains ~15.000 words (don't know how many sentences), but increasing |
@orzechow Please open a new issue with an example document to reproduce the issue. It's not possible to help you with just this info. |
Describe the bug
It seems like it is possible by inducing a spellcheck while another spellcheck is running to cause an infinite loop when using large documents. I have a book (thesis) with 20 000 word chapters per file which cause issues.
As I have managed to work around it with massively increasing the sentence cache and the heap size the issue is not critical to me. But it indicated, AFAIK, that something is a bit fishy with the behavior of cancelling RPCs.
If needed I can reset to default values and recreate an infinite log, but I'd rather avoid it :-)
Steps to reproduce
Steps to reproduce the behavior:
ltex.checkFrequency
is manual or save do whatever you have to do to make the spellchecking start)Expected behavior
I expect the spellcheck to finish in reasonable time, i.e. a couple of minutes at bootup and a couple of seconds after that, and in particular to finish at all.
I seem to be able to avoid it by increasing
ltex.sentenceCacheSize
to something large (I set it to 50 000). Currently I am also running with"ltex.java.maximumHeapSize": 8192
and I cannot recreate the issue with those settings.Sample document
A 20 000 word document with proper sentences (I do not seem to induce it with a 20 000 word Lorem ipsum, possibly because the sentences repeat?)
LTeX configuration
"LTeX Language Server" log file
Spread over 10 min or so, sometimes it gets stuck "forever", I have witnessed 24h+ of accumulated CPU time when I let it run overnight. I do not have a log from these 24h+ sessions of repeated spellchecking.
Usually the log "stops" (i.e. waits for the next iteration) at the first paragraph of the document, which confuses me:
Does it check the document in reverse or is this a clue for something?
"The ecology\n\n Blah blah" represents the start of the chapter, i.e.
I also wonder if all the cancel notifications can provide a clue? (there can be hundreds of them which only shows up in the log if the server actually finishes)
are a piece of the puzzle?
Version information
List here the version information of the relevant software.
Additional context/information
As mentioned, increasing heapsize and cache size seems to do the trick.
I guess many requests for spellcheck gets queued up since the cache is not large enough so each individual request takes quite a bit of time. And then something goes completely haywire when I manage to queue up enough spellchecks to keep it running all night?
Maybe something is buggy with the RPC calls for cancelling already running requests?
The text was updated successfully, but these errors were encountered: