for a long time now I observed a strange repl behavior, which I always contributed to emacs + vterm. However I now realised, that it also appears in different terminals (iterm2 on mac and windows terminal/wsl) so it seems to be related to Julia itself.
The problem is, that pasting code into the REPL is much slower when pasting while the repl is busy then when pasting while idle.
Steps to reproduce:
open julia --startup-file=no
past longish text: appears instantly
call some function which keeps julia busy for some time (e.g. sleep(5))
paste the same text while Julia is busy
text appears instantly
Once the sleep returns, the pasted text re-appears very slowly at the prompt (while CPU usage goes crazy) before its being executed.
Example video:
Any idea what causes this behavior? It isn’t to bad the repl, but is quite annoying in my emacs workflow where I constantly send large chunks of text to the repl and it .
So the video in the first post was windows terminal but julia running under Ubuntu in WSL. I’ve also seen this behavior in Iterm2 under MAC and vterm in emacs.
Just now I tried it in the windows terminal with windows-julia running in powershell, and there it does not matter whether the repl is busy or not, the pasted text appears slowly letter by letter like in the video above. Very strange that this doesn’t seem to be easily reproducible by others…
Maximum buffer size for CMD is limited by available memory, but the default is typically 300 lines
The same goes for PowerShell, but the default is usually 1000 lines. However, you can change these settings.
The point is every shell has its own limited Buffer Size, and I guess you are exceeding that.
You typically see something like this #define LSH_RL_BUFSIZE 1024 in their source.
When you execute a program, let’s say Julia in a shell, the shell creates a subprocess/subshell afterward the Subshell is your Julia REPL.
While the REPL is running the terminal mode gets reset, in case the expression that you’re running wants to use the terminal itself. The particular behavior observed here is that the REPL uses bracketed paste mode to distinguish between pasted in code and typed in code. In particular, pasted in code:
Removes julia>, shell> etc prefixes
Makes tabs ident, not to tab completion
Disables auto-indent.
Gets processed all at once, rather than character by character.
One could optimize the REPL by not redrawing after each character, but the fundamental behavior observed here is fundamental in the sense that there’s an explicit design objective to allow the running code to take over the REPL, which requires a mode reset.