Tuesday, November 14, 2017

Re: Vim surprisingly slow?

On 2017-11-14 18:17, Christian Brabandt wrote:
> On Di, 14 Nov 2017, Nazri Ramliy wrote:
>
> > On Sun, Nov 12, 2017 at 10:21 PM, Tim Chase
> > <vim@tim.thechases.com> wrote:
> > > If I change the "exec" to an "echo", it's as fast as I expect.
> > >
> > > Any idea what might be making the exec so slow?
> >
> > It's vim writing to disk that makes it slow. I ran it on SSD it's
> > fast, on a spindle disk it's slow. I use fatrace[1] to see the
> > file create/write/close operations done by vim. So vim is writing
> > to the file for each line that matches the pattern.
>
> So how slow is it, if we skip the `.w >> output` part of the
> command, but rather gather the matches in a list?

Using this as my test:

:let a=[] | g/.*name":"\([^"]*\)".*card":"\([^"]*\)".*/let
s=substitute(getline('.'), '.*stamp":"\(\d\+\)-\(\d\+\)-\(\d\+\).*',
'\1\2\3','').'.txt'|s//\1,\2/|exec "call
add(a,\"".s.getline('.')."\")"

The above makes the following changes:

- initializes "a" to be an empty array

- changes the ".w! >>".s after the exec to a "call add(a,"...")"
accessing both the filename and the text-line in question

Comparing timings, it's inappreciably different from the "echo"
version, so no major speed issues there. It seems to be the ".w!>>"
that is the bottleneck.

Thanks again!

-tim




--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment