News for hackers. Stuff that matters.
Re:A vision of a multi-threaded Emacs by chrsig on Monday May 30, 2022 @12:46PM (#31560845)
This is putting a lot of blame on the user, who likely has no clue how emacs i/o behaves.

> if you're experiencing I/O hangs, it's either misconfiguration or bad code in a package that you loaded

I mean...yes. That's the issue. The issue is that it's possible to have i/o hangs caused by misconfiguration or elisp packages.

The solution isn't to tell the user to do something different, it's to make it so that elisp execution can't cause i/o hangs.

edit: to a be a bit more precise with language: "i/o hang" should be interpreted as "making the UI unresponsive or preventing other tasks from completing".

Re:A vision of a multi-threaded Emacs by jrockway on Monday May 30, 2022 @05:45PM (#31563966)
> This is putting a lot of blame on the user

I think you're missing the point. Emacs already contains all the support necessary to make LSP not lock up the UI, LSP simply doesn't use it. So if you say "LSP is a great use case for multi-threaded Emacs", that's not correct.

The problem with LSP specifically is that Emacs doesn't really know what the language server is going to do, and if it let you update the text while the language server was also updating the text, it would have to have some way to merge the changes that you made while the language server was busy. There would need to be some spec for that, or more likely, another trip to the language server to figure out what to do. You could, of course, edit the text while that second trip was happening, and this algorithm never converges to a finished state. So, it locks the UI so you can't make any edits until the text from the language server comes back. That's the easy way out, but at least it results in an algorithm that terminates.

The way to fix this is to figure out where the time is being spent. If it's on JSON marshaling/unmarshaling, speed that up. If it's because the language server is slow, speed that up. The only compromise right now would be to let you edit buffers in a different project while the language server is processing something. I don't think anyone wants to do that; "I don't want LSP to lock up Emacs" really means "I want my language server to perform all operations instantly." So get out that profiler for your language server, I think.

Re:A vision of a multi-threaded Emacs by bitwize on Monday May 30, 2022 @06:55PM (#31564504)
> I think you're missing the point.

I don't. "The only thing that matters in software is the experience of the user." The Emacs user experience is full of I/O hangs; the VSCode experience is not. This is a problem that needs to be solved if Emacs is ever to have a significant installed base again.

Re:A vision of a multi-threaded Emacs by armitron on Monday May 30, 2022 @07:59PM (#31564866)
> The Emacs user experience is full of I/O hangs

I can't remember the last time I had an I/O hang in Emacs. I'm also fairly active in the mailing list and various forums, I/O hangs are not really what's being discussed day to day.

So I have to ask, are you projecting or what makes you say something like that?

Re:A vision of a multi-threaded Emacs by appletrotter on Monday May 30, 2022 @08:13PM (#31564940)
As a third party in this conversation, and someone who uses emacs daily - I/O hangs seem to be something that is a pretty frequent issue for users.

My emacs likes to crash sometimes, usually a few times a week. Hopefully I’ll be able to take some time to bisect my config and see what’s going on. Looks like a memory leak.

Re:A vision of a multi-threaded Emacs by Kaze404 on Tuesday May 31, 2022 @07:08AM (#31568179)
To add to this, my Emacs never crashes but at least once a week I'll run an innocent command (sometimes just opening magit) and it will become unresponsive indefinitely, with the only way of closing it being sending a kill command from the terminal.
Re:A vision of a multi-threaded Emacs by gjadi on Wednesday June 01, 2022 @09:59AM (#31581894)
If your emacs freezes, you can often recover it by sending the USR2 signal. When it receives this signal, Emacs will drop in the debugger.
Re:A vision of a multi-threaded Emacs by anthk on Tuesday May 31, 2022 @11:36AM (#31570757)
Sadly it's common with Gnus.
Re:A vision of a multi-threaded Emacs by hatmatrix on Monday May 30, 2022 @07:27PM (#31564697)
If this is the core of the problem, how does VSCode solve it? It seems users report less latency issues with VSCode - have they figured out how to handle the two-way communication better?
Re:A vision of a multi-threaded Emacs by jrockway on Monday May 30, 2022 @10:01PM (#31565453)
For the purposes of this argument I went and installed VSCode. I cloned kubernetes/kubernetes, opened a random file, added fmt.Println("hello") at the wrong indentation level somewhere, and pressed save. While gopls is initializing, it pops up a thing saying "waiting for code actions from the language server" (or similar; it wants the language server to "gofmt" the file). After that completes, the line I wrote appears at the right indentation level in the editor, but what's on disk is `fmt.Println("h` at the wrong indentation level.

Emacs behaves in a different but still incorrect way. It writes the entire fmt.Println statement at the wrong indentation level, locks up for a while, and decides that there was no formatting to do. VS Code will be fast after a while, but Emacs never gets fast; every reformat request locks up the UI for several seconds and doesn't actually reformat. VS Code remains responsive, but it's difficult to get the reformatted text on to disk. (Sometimes it does it, though.)

My main conclusion is that you're screwed if you have to work on k8s day to day. But on a more serious note, this isn't really an issue that can be solved with a UX tweak; the class of problem is "the optimal algorithm for providing instant hints on a codebase that is 214k lines hasn't been discovered yet". Yes, editors can let you mutate the text while it's working on something in the background; and if you turn of language server support that's fine. The key problem is merging your edits with its set of assumptions, and that's what's going to be slow.

Re:A vision of a multi-threaded Emacs by medstrom on Monday May 30, 2022 @02:05PM (#31561784)
How would you make it impossible to make the UI unresponsive? Given that lots of packages directly want to do stuff with UI?
Re:A vision of a multi-threaded Emacs by chrsig on Monday May 30, 2022 @02:40PM (#31562163)
I'm not going to have a great answer for how, especially in something with as much legacy as emacs. And I certainly don't mean to imply that solving the problem is easy (or possible for 100% of cases), or otherwise detract from efforts that the community has made.

My intent was to highlight on what a good solution looks like from a user perspective.

Off the top of my head, in an incredibly hand-wavey fashion:

A quick win would be to set a timeout on every single i/o action, with the default timeout being quite low. That doesn't remove the problem, but it'd probably be a good start towards easing the user pain. Bringing an indefinitely long hang down to 1s is a win.

For a total solution, I'd consider looking into implementing a concurrency model with a preemptive scheduler, probably using erlang as inspiration. have updates to the ui becoming a message sent to the ui inbox, and the routine for rendering the ui just reading from the inbox and applying the given command.

This is without thought to how to actually implement that, and what implications it would have on legacy elisp, or how legacy elisp could be brought into a CSP world without breakage.

So just some armchair architecting on a day off for a project I've never worked on :)