~technomancy/fennel

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
2 2

[PATCH] Improving the REPL loading feedback

Details
Message ID
<20200822133233.373676-1-gbaptistas@protonmail.com>
DKIM signature
pass
Download raw message
Patch: +16 -11
Hi!

This patch improves user feedback when loading the repl.

I found that the problem is related to how the Javascript Event Loop works. The talk "What the heck is the event loop anyway?" by Philip Roberts was a joy of knowledge!

This patch does not solve the entire problem: The fact that the browser still freezes during the loading and the page does not respond until the repl is loaded makes me crazy.

I will try to do some experiments, and if it works, I send a second patch. Probably some solution using js async feature or Web Workers will do the trick.

---
 init.lua | 27 ++++++++++++++++-----------
 1 file changed, 16 insertions(+), 11 deletions(-)

diff --git a/init.lua b/init.lua
index a55516e..94fbc55 100644
--- a/init.lua
+++ b/init.lua
@@ -126,17 +126,22 @@ local repl
-- loading Fennel at the top level breaks scrolling because browsers
-- are terrible; so we load when the input element gets focus
function input.onfocus()
   -- setting input.onfocus to nil has no effect, somehow
   if repl ~= nil then return end
   _G.print("Loading...")
   local fennel = require("fennel/fennel")
   package.loaded.fennel = fennel
   repl = coroutine.create(fennel.dofile("repl.fnl"))
   assert(coroutine.resume(repl))
   welcome = "Welcome to Fennel " .. fennel.version ..
      ", running on Fengari (" .. _VERSION .. ")"
   _G.print(welcome)
   _G.printLuacode("Compiled Lua code")
    -- setting input.onfocus to nil has no effect, somehow
    if repl ~= nil then return end
    _G.print("Loading Fennel...")
    js.global:setTimeout(function()
        local fennel = require("fennel/fennel")
       package.loaded.fennel = fennel
       _G.print("Loading REPL...")
       js.global:setTimeout(function()
           repl = coroutine.create(fennel.dofile("repl.fnl"))
           assert(coroutine.resume(repl))
           welcome = "Welcome to Fennel " .. fennel.version ..
              ", running on Fengari (" .. _VERSION .. ")"
           _G.print(welcome)
           _G.printLuacode("Compiled Lua code")
        end)
    end)
end

function input.onkeydown(_, e)
-- 
2.28.0
Details
Message ID
<87a6ym7jb0.fsf@hagelb.org>
In-Reply-To
<20200822133233.373676-1-gbaptistas@protonmail.com> (view parent)
DKIM signature
missing
Download raw message
gbaptista <gbaptistas@protonmail.com> writes:

> This patch does not solve the entire problem: The fact that the
> browser still freezes during the loading and the page does not respond
> until the repl is loaded makes me crazy.

It's not a complete solution but it's a big improvement! At least we
have a loading message now so the user doesn't think it's hung or
broken.

I've applied this patch and deployed it; thanks!

> I will try to do some experiments, and if it works, I send a second
> patch. Probably some solution using js async feature or Web Workers will
> do the trick.

Seems like this would be easier if the Fengari compiler could be made to
yield every so often, but sadly since it's JS, it doesn't have coroutines.
But maybe we could at least split up the parsing and the compiling and
the loading of fennel.lua?

-Phil
Details
Message ID
<addfe7a2-fad7-8817-0aa6-2f5dbdf522f8@protonmail.com>
In-Reply-To
<87a6ym7jb0.fsf@hagelb.org> (view parent)
DKIM signature
pass
Download raw message
On 8/22/20 1:10 PM, Phil Hagelberg wrote:

> Seems like this would be easier if the Fengari compiler could be made to
> yield every so often, but sadly since it's JS, it doesn't have 
> coroutines.
> But maybe we could at least split up the parsing and the compiling and
> the loading of fennel.lua?

I did an experiment, and 90% of the time is spent on loading the
complete Fennel source; the other 10% is for the REPL. I'm not sure how
much this part would be splittable.

I believe that we can use a Web Worker without changing too much code.

I sent a patch with a suggestion.
Review patch Export thread (mbox)