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

pasting a long string results in a hang and lots of ^G's #219

Closed
aaronjensen opened this issue Feb 19, 2017 · 12 comments
Closed

pasting a long string results in a hang and lots of ^G's #219

aaronjensen opened this issue Feb 19, 2017 · 12 comments

Comments

@aaronjensen
Copy link

This is on develop c9a51e0

paste

It's probably related to #141, and setting ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE=15 works around it, but it seemed odd and most people won't set that so I thought I'd report it.

@ericfreese
Copy link
Member

ericfreese commented Feb 19, 2017

I'm actually not quite able to reproduce this. When I have bracketed-paste-magic loaded, I do see a flash of ^G characters, but they are quickly removed. Can you share your setup? What version of zsh, what OS, what terminal emulator, etc.? Can you reproduce with only the following?

% zsh -f
%% autoload -Uz bracketed-paste-magic
%% zle -N bracketed-paste bracketed-paste-magic
%% source zsh-autosuggestions.zsh
%% <paste>

Edit: Looks like I'm able to consistently reproduce this with just the following (no bracketed-paste-magic):

% zsh -f
%% source zsh-autosuggestions.zsh
%% foo() { zle -U - $(printf '%*s' "100" | tr ' ' "a") } # Send 100 "a" chars to the zle input stack
%% zle -N foo
%% bindkey ^T foo
%% <ctrl+T>

@aaronjensen
Copy link
Author

aaronjensen commented Feb 19, 2017

It's a much faster flash w/ the minimum repro. I'll see if I can track down what other bits are exacerbating it.

I'm on OS X 10.11 w/ iterm2 3.0.14 and my zshrc is here https://github.com/aaronjensen/dotfiles/blob/master/zshrc (though w/ ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE commented out)

@aaronjensen
Copy link
Author

zsh-users/zsh-syntax-highlighting appears to cause it to hang for longer in my config.

If I add source zsh-syntax-highlighting.zsh to your repro above then it is quite a bit slower when I paste, but it doesn't hang, so there may be some other thing that speeds up the paste in my config but causes it to hang (perhaps the repro you've listed isn't enough to make async work?)

slow

@ericfreese ericfreese mentioned this issue Feb 20, 2017
13 tasks
@ericfreese
Copy link
Member

I've added this to the todo list for #218.

It looks like the ^Gs are from the async mechanism getting overloaded with too much input coming in too quickly. Might have to add some logic to keep the client and server in sync so the client backs off a bit if the server stops responding, but that will likely only add to the delay with bracketed-paste-magic... Widgets for disabling/enabling z-asug might be the best compromise here. Those widgets could be added to bracketed-paste-magic's paste-init/paste-finish hooks to disable suggestions while pasting.

@aaronjensen
Copy link
Author

Widgets for disabling/enabling z-asug might be the best compromise here

This sounds great to me. I tried doing it but I had no idea how... I look forward to seeing how you are able to do this so I can learn from you.

ericfreese added a commit that referenced this issue Feb 28, 2017
ericfreese added a commit that referenced this issue Mar 3, 2017
ericfreese added a commit that referenced this issue Mar 3, 2017
[GitHub #219]

Intended to be helpful for folks using bracketed-paste-magic and other
widgets that use `zle -U`.
ericfreese added a commit that referenced this issue Mar 3, 2017
ericfreese added a commit that referenced this issue Mar 3, 2017
[GitHub #219]

Intended to be helpful for folks using bracketed-paste-magic and other
widgets that use `zle -U`.
ericfreese added a commit that referenced this issue Mar 3, 2017
ericfreese added a commit that referenced this issue Mar 3, 2017
[GitHub #219]

Intended to be helpful for folks using bracketed-paste-magic and other
widgets that use `zle -U`.
@ericfreese
Copy link
Member

@aaronjensen Added autosuggest-enable and autosuggest-disable widgets in #223. Please pull down that branch and add autosuggest-disable to the bracketed-paste-magic paste-init hook and autosuggest-enable to the paste-finish hook and let me know if that solves this problem.

There's also a patch submitted upstream that should allow the plugin to detect if there are characters pending on the input stack via zle -U and not fetch a suggestion if so.

@aaronjensen
Copy link
Author

Unfortunately, I'm still seeing the slow paste/flash of G's. Maybe I'm doing something wrong?

$ zsh -f
aaronmbp% autoload -Uz bracketed-paste-magic
aaronmbp% zle -N bracketed-paste bracketed-paste-magic
aaronmbp% source zsh-autosuggestions.zsh
aaronmbp% zstyle :bracketed-paste-magic paste-finish autosuggest-enable
aaronmbp% zstyle :bracketed-paste-magic paste-init autosuggest-disable

aaronmbp% "Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?"

@ericfreese
Copy link
Member

I think paste-init and paste-finish expect functions instead of widgets so you could try defining a couple functions:

pasteinit() {
  zle autosuggest-disable
}

Then

zstyle :bracketed-paste-magic paste-init pasteinit

And the same for paste-finish

@aaronjensen
Copy link
Author

Ah, thanks. That makes it a bit faster it seems, but it still takes more time than w/o it enabled.

$ zsh -f
aaronmbp% autoload -Uz bracketed-paste-magic
aaronmbp% zle -N bracketed-paste bracketed-paste-magic
aaronmbp% source zsh-autosuggestions.zsh
aaronmbp% function ad {
zle autosuggest-disable
}
aaronmbp% function ae {
zle autosuggest-enable
}
aaronmbp% zstyle :bracketed-paste-magic paste-init ad
aaronmbp% zstyle :bracketed-paste-magic paste-finish ae

disable

@aaronjensen
Copy link
Author

Also, when it reenables, it autosuggests based on an empty prompt (the clear at the end)

@ericfreese
Copy link
Member

Also, when it reenables, it autosuggests based on an empty prompt (the clear at the end)

6e46ac9 should fix this. Not quite sure why it's still slow. Will have to do a little more research into that, but I think I'd be ok releasing as-is now since it does work, it's just a little slow.

@aaronjensen
Copy link
Author

It doesn't actually seem to make much difference, to be honest. W/ zsh -f it seems to prevent the ^G flashes, but on my normal config (which includes syntax hightlighting) the paste speed is the same with or without the disable/enable. It's faster than it was in the past (even w/o disable/enable), but I'm guessing that that is due to async.

One thing I notice as well is that ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE=15 no longer has any impact. It used to be that every character after the 15th would appear in one fell swoop. Now they still come in one at a time. I wonder if there's something w/ the async addition that makes the normal case faster but still has some additional overhead that the non-async method didn't have in the paste case.

It'd be great if it was instant like it is w/o it, but it's not a huge deal as it is now because it's quite a bit faster than it was pre-async, I think.

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

No branches or pull requests

2 participants