Skip to content

Conversation

adamharrison
Copy link
Member

So there were a couple issues here:

  1. Coroutines, even in foreground, were only running on events, with the cursor blink cycle. This is wrong; if we're in foreground, and the coroutine requests that it should be serviced in 10ms, it shouldn't take 400ms.
  2. I dun goofed, and mixed up then/else in a ternary; the thread watching for directory changes was sleeping when changes were happening, and revving like crazy when they weren't. This was masked by the above issue, now fixed.

@adamharrison adamharrison requested review from jgmdev and removed request for jgmdev February 3, 2023 19:47
@adamharrison adamharrison marked this pull request as draft February 3, 2023 19:48
@jgmdev
Copy link
Member

jgmdev commented Feb 3, 2023

Hopefully this change will bring some responsiveness to the LSP plugin and other things. I remember LSP performed better when I first developed it but at some point lite-xl introduced a change that made things less responsive. I guess it was this cursor blink + coroutine sync issue or maybe a placebo effect from my side :), testing the patch and so far so good.

@adamharrison adamharrison marked this pull request as ready for review February 3, 2023 19:57
@adamharrison
Copy link
Member Author

OK, I think we're good to go. Should call step only as much as it did before, but will now resume coroutines if in focus at their desired timings.

@jgmdev
Copy link
Member

jgmdev commented Feb 15, 2023

testing it with lsp now, and for some reason typing is more lagged...

@adamharrison
Copy link
Member Author

Could be that because it's actually returning when you request it now, you may need to adjust your timeouts to back off a bit, as they'll be getting called how much they should be now, instead of a semi-random amount of times.

@jgmdev
Copy link
Member

jgmdev commented Feb 15, 2023

Also with this something is causing wheel scrolling major lagging

@adamharrison
Copy link
Member Author

We may have to adjust some of the timeouts; if they're used to things happening with events, they could be overly aggressive.

@jgmdev
Copy link
Member

jgmdev commented Feb 15, 2023

Leaving this change here for reference which fixes the lag issue mentioned above which was caused by coroutine.yield() without any timeout parameter as discussed on discord:

diff --git a/data/core/init.lua b/data/core/init.lua
index 00322121..386f0276 100644
--- a/data/core/init.lua
+++ b/data/core/init.lua
@@ -1396,11 +1396,10 @@ local run_threads = coroutine.wrap(function()
           else
             core.threads[k] = nil
           end
-        elseif wait then
+        else
+          wait = wait or 0.0025 -- default to 400 times per second if wait not specified on coroutine.yield()
           thread.wake = system.get_time() + wait
           minimal_time_to_wake = math.min(minimal_time_to_wake, wait)
-        else
-          minimal_time_to_wake = 0
         end
       else
         minimal_time_to_wake =  math.min(minimal_time_to_wake, thread.wake - system.get_time())

So far testing seems to indicate better lsp responsiveness without any further changes.

@sammy-ette
Copy link
Contributor

works fine for me

@adamharrison adamharrison merged commit 2cae7c5 into lite-xl:master Mar 28, 2023
@Guldoman
Copy link
Member

Weren't there issues with yields of 0 and nil?

@adamharrison
Copy link
Member Author

It's not an issue, per-se; if you yield 0, you shouldn't wait anything.

The only issue is nil. Which is debatable as to what the appropriate behaviour should be. The current behaviour, even before this PR, technically is a wait of 0.

I'm cool with a default wait (and can implement that, if you like), like jgm said, but that technically would be a change, which I'm not sure if that'd be expected.

@adamharrison
Copy link
Member Author

adamharrison commented Mar 28, 2023

OK; so upon review; jgm is correct, there's a slight issue with nil, in that wake times will go negative. This shouldn't actually lead to much difference in behaviour, but I'll make his changes to make it more clear here; though I don't know about the default of blank being non-zero.

takase1121 pushed a commit to takase1121/lite-xl that referenced this pull request Nov 30, 2023
* Made coroutines make more sense, and fixed a bug.

* Fixed typo.

* Additional checking for off-cycles.

* Fixed issue with calling step too much.

* If we have no redraw, set next step time for next frame.

* Added in `now` variables to reduce calls.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

4 participants