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

Use a timeout of 5s for searchpairpos #90

Closed
wants to merge 1 commit into from

Conversation

blueyed
Copy link
Member

@blueyed blueyed commented Sep 22, 2017

The timeout is supported with Vim 7.3.429 at least.

In case of issues (breaking older Vims), this could be wrapped to
fallback to some (higher) max offset.

Fixes #64.

TODO:

  • test?! (via internal/new setting and lowering it there?!)
  • doc

Would a (documented) setting for this be useful?
Is 5s a sane default?

The timeout is supported with Vim 7.3.429 at least.

In case of issues (breaking older Vims), this could be wrapped to
fallback to some (higher) max offset.

Fixes #64.
@mgedmin
Copy link

mgedmin commented Sep 22, 2017

Manual testing: it takes 15 seconds to re-indent a flat list iteral with 1000 items (one per line). Indenting just a single line at the end of the list feels instant.

A more complicated 273-line nested dict literal took 38 seconds to indent. It's very noticeable how the first few blocks of 50 lines go fast and the last ones are very slow. Quadratic behavior, I suppose.

Hitting o near the end of the 273-line dict literal requires between 1 and 2 seconds to compute the correct indentation. That could get annoying quickly.

For the use case of reindenting a whole block I would prefer slow but correct behavior. For the use case of just appending one line as I type, I'd prefer fast (up to 0.5s) but wrong.

I think a documented setting would be useful: I could increment it temporarily if I discover the need to reindent a large literal I just pasted, after I discover that the default timeout is too short to do it correctly.

@blueyed
Copy link
Member Author

blueyed commented Sep 22, 2017

So the timeout is per lookup then, and should be shorter than 5s for sure.

Can you provide the 273-line example, so that it could be profiled?
Also the 1000 items list might be useful.
Both with instructions on what operations you do.

Or profile it yourself, using Vim's :profile.
There is certainly some optimizations to be made here, and it clearly shows.

We can probably detect if it's while typing or indentation (= operator).

@mgedmin
Copy link

mgedmin commented Sep 22, 2017

The 1000-item list was synthetic:

def fb():
    x = [
        'test',
        ... repeated 1000 times
    ]

The test I did was selecting the block with Vi[, indenting it with >, then restoring the indent with gv=.
The other test was hitting O near the end of the literal, to see if the new line gets the right indent.

The JSON blob I'll provide later, when I get to a computer. I performed the same two tests, except I used Vi{ and didn't have to break correct indentation, since the blob I had was already misindented (missing all leading space).

@mgedmin
Copy link

mgedmin commented Sep 23, 2017

Here's the JSON blob: https://gist.github.com/mgedmin/a32a3b8c188a8cea1204b98e015562f8. (My use case was to paste it into my application code temporarily to stub some data. JSON is practically Python, I just have to change true to True and null to None.)

Very curiously, today I cannot reproduce my timings -- indentation is very fast. Even if I reindent the entire 1278-line test file (the synthetic list plus this json blob), it takes just 10 seconds. And I'm pretty sure I didn't do any git pulls in any vim plugins, so I'm not sure what might have changed! I do git pull and rebuild my vim practically every day, but I don't think any optimizations happened recently there either.

@blueyed
Copy link
Member Author

blueyed commented Sep 30, 2017

Just a note: the 5s timeout is much too long, especially when it is used "interactively" after e.g. o.

@blueyed
Copy link
Member Author

blueyed commented Oct 5, 2017

See #91 for a simple fix for this.

In the long run I would like to have some caching / more logic there, but #91 seems to behave well.

@blueyed blueyed closed this Jul 26, 2018
@blueyed blueyed deleted the searchpairpos-timeout branch July 26, 2018 09:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants