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

Livebook crashing attempting to open a livebook. #1098

Closed
Adzz opened this issue Apr 10, 2022 · 12 comments
Closed

Livebook crashing attempting to open a livebook. #1098

Adzz opened this issue Apr 10, 2022 · 12 comments

Comments

@Adzz
Copy link
Contributor

Adzz commented Apr 10, 2022

Environment

  • Elixir & Erlang/OTP versions (elixir --version): elixir 1.13.3-otp-24, erlang 24.1.7
  • Operating system: mac / unix
  • How have you started Livebook (mix phx.server, livebook CLI, Docker, etc): livebook server
  • Livebook version (use git rev-parse HEAD if running with mix): Livebook 0.5.2
  • Browsers that reproduce this bug (the more the merrier): firefox
  • Include what is logged in the browser console: nothing
  • Include what is logged to the server console: nothing

Current behavior

I have been experimenting with generating livebooks from module docs. I generated a livebook from Elixir's Enum module, but I cannot open it. Livebook hangs for a long time.

Expected behavior

That I can open the livebook 😄

@josevalim
Copy link
Contributor

I don’t think we have the commit SHA in this repo. Are you running a fork? In any case, can you make sure you have this commit applied: a70f53d

@Adzz
Copy link
Contributor Author

Adzz commented Apr 10, 2022

Yea apologies I pasted the wrong commit sha originally, I updated the comment with the version.

I just tried cloning the repo and using latest master, so git rev-parse HEAD = a280224

I still get the same issue.

UPDATE - It did eventually load this time, it just took a long time. The livebook also struggles to evaluate all the cells.

I wonder if the livebook is just too large or something

@jonatanklosko
Copy link
Member

It's related to notebook size, yeah.

The initial hang during import/navigation is caused by editor initialization, which takes a long time for so many editors. Actually, the initialization happens when mounting hooks, so the session page is only shown after all editors are initialized; we could defer the initialization (though a bit tricky), so that we show session skeleton instead, but this doesn't change the fact that all the initializations need to happen and we won't avoid it.

As for slow evaluation, patching the DOM takes a long time (0.5s - 2s for a single diff). Maybe we could improve some of that with more sateful components.

@Adzz
Copy link
Contributor Author

Adzz commented Apr 11, 2022

Thanks for digging into it more! I was a little suprised because I didn't think the notebook was that large - certainly within the realm of what vscode should be able to handle. I assume it's the number of elixir cells that are problematic, rather than too much markdown eg?

We could perhaps add some guidance somewhere around max size if nothing else!

@jonatanklosko
Copy link
Member

jonatanklosko commented Apr 11, 2022

I assume it's the number of elixir cells that are problematic, rather than too much markdown eg?

Yeah, note in our case it's not a single code editor, but a bunch of those, and unfortunately mounting an editor is a synchronous operation.

Your case is a bit specific because you took an existing large notebook-like file, but most of the time people write notebooks in the first place, and I think they would notice if things slowed down.

There's likely no obvious max size, because it heavily depends on how fast the browser operates, so it will vary across hardwares.

@Adzz
Copy link
Contributor Author

Adzz commented Apr 11, 2022

Yea appreciate my use case may be unique. The reason for generating livebooks at all is so you can have one source of truth for all documentation.

One idea that might be very naive - currently each Elixir cell is a whole Monaco editor, but presumably the editor allows multiple buffers - as in in VSCode I can press ctrl+n and a new file / buffer thing appears.

Could we have one Monaco instance on the page and have each subsequent elixir cell be a file / buffer?

@jonatanklosko
Copy link
Member

jonatanklosko commented Apr 11, 2022

@Adzz it is possible to create a single editor instance and multiple document models, then switch the current model. This allow for implementing tabs (ref). In our case, however, we need to all the documents at once, so we need multiple instances.

Jose pointed out that we could initialize editor for markdown cells lazily, because it's hidden by default, so that's one thing I will look into.

@Adzz
Copy link
Contributor Author

Adzz commented Apr 11, 2022

Oh cool, tabs is exactly what I had in mind

however, we need to all the documents at once,

I assume the missing word is "load" - either way I trust you.

@jonatanklosko
Copy link
Member

jonatanklosko commented Apr 11, 2022

Ah sorry, I meant that we need to show all the documents at once, or in other words have all the tabs open (each cell being one).

@jonatanklosko
Copy link
Member

With #1102 it should open more quickly, though initializing all the code editors will still take a moment. As for evaluation, I don't think we can easily avoid full DOM patches without breaking the page down into more stateful components and pushing updates to them directly, but orchestrating all of that is too much complexity. Maybe some future optimisations in LV will help with that.

All that said, I'm gonna close this one :)

@RichMorin
Copy link

RichMorin commented Aug 8, 2022

I'm confused by this: "in our case it's not a single code editor, but a bunch of those". Are you saying that Livebook is setting up an instance of a single code editor (eg, Monaco) for each cell, or that it is setting up instances of multiple editors for each cell? If it's the latter, maybe a user preference could specify which editor(s) are desired.

@jonatanklosko
Copy link
Member

Are you saying that Livebook is setting up an instance of a single code editor (eg, Monaco) for each cell

Correct, each cell has its own editor because they are visible all at once (as opposed to tabs in VS Code, for example).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants