svermeulen/vim-easyclip

Make EasyClip load on-demand using vim-plug

sassanh opened this issue · 12 comments

I'm trying to optimize my vim's startup time. Investigating load time of different plugins I found that EasyClip is taking around 150ms to load. The only plugin that used more time was YouCompleteMe and it took around .5s. I was able to make YCM load on demand using the instructions on vim-plug (making YCM on-demand is an example of on-demand feature of vim-plug.) I thought it'd be great if I could make EasyClip load only when I issue a yank or paste command. Could you please provide some instructions for this purpose?

I don't know if it's possible at all, as there may be a dd before easyclip loads or things like that. I wonder why it's taking so long to initialize, maybe we could work on that instead of making it load on-demand.

We might be able to make it load more lazily - right now it does just load everything on startup. I'd be curious to learn which parts are taking the most time, if you do end up doing some profiling please share. Unfortunately I don't have time right now to do much work here as much as I would like to help

Look at this:

FUNCTION  EasyClip#Shared#Init()
Called 1 time
Total time:   0.154002
 Self time:   0.000193
...

    1   0.056135   0.000011     let yankHeadBeforeLoad = EasyClip#Yank#GetYankstackHead()

    1   0.041174   0.000084     call EasyClip#Shared#LoadFileIfChanged()

    1   0.056606   0.000011     let newYankHead = EasyClip#Yank#GetYankstackHead()

and this:

FUNCTION  EasyClip#Yank#GetYankInfoForReg()
Called 2 times
Total time:   0.112636
 Self time:   0.112279

count  total (s)   self (s)
    2   0.112630   0.112274     return { 'text': getreg(a:reg), 'type': getregtype(a:reg) }

and this:

FUNCTION  <SNR>141_VisualModeYank()
Total time:   0.041090
 Self time:   0.017168

count  total (s)   self (s)
    1              0.000007     if !g:EasyClipShareYanks
                                    return 0
                                endif

    1              0.000026     if !filereadable(s:shareYanksFile)
                                    return 0
                                endif

                                " Only read in yanks from disk if the file has been modified since
                                " last read
    1              0.000015     let l:currentYanksFileModificationTime = getftime(s:shareYanksFile)
    1              0.000005     if l:currentYanksFileModificationTime <= s:mostRecentYanksFileReadTime
                                    return 0
                                endif

    1              0.000005     let s:mostRecentYanksFileReadTime = l:currentYanksFileModificationTime

    1              0.002230     let l:allYanksFileContent = readfile(s:shareYanksFile)
    1              0.000012     let l:allYanks = []

  501              0.000828     for allYanksFileContentLine in l:allYanksFileContent
  500              0.006657         let l:allYanksItem = eval(allYanksFileContentLine)
  500              0.005051         let l:allYanksItem.text = substitute(l:allYanksItem.text, s:newLinePatternRegexp, "\n", 'g')
  500              0.001449         call add(l:allYanks, l:allYanksItem)
  500              0.000552     endfor

    1              0.000003     if len(l:allYanks)
    1   0.023805   0.000024         call EasyClip#Yank#SetYankStackHead(remove(l:allYanks, 0))
    1   0.000028   0.000018         call EasyClip#Yank#SetYankStackTail(l:allYanks)
    1              0.000001     endif

    1   0.000135   0.000005     call EasyClip#Yank#SyncNumberedRegisters()
    1              0.000003     return 1

First one obviously is related to loading the yanks list from file, others seems to be related to that huge list too. I guess if we could manage to make it lazy load the list of yanks from file or use nvim's async feature it'd solve the load time problem.

Ah yes - not surprising that loading the shared yanks to/from file is the issue. For some reason I assumed that you had that off (which is the default).

Do you have g:EasyClipYankHistorySize set to 500? I looks like it from the profile log so just want to make sure

I'm not sure you can lazy load that list of yanks very easily, since the user could access it directly through registers (rather than through paste / yank / move commands). Also, I'm not sure it would really be worth it anyway since you would need to have it loaded pretty quickly anyway, unless you're using Vim just for reading text and not actually changing or yanking anything.

Using nvim to load/save in the background might make sense though

I see. I thought maybe there's a tiny mistake somewhere that's making it take too long, but now I think it doesn't worth to lazy load it too. I think I can reduce g:EasyClipYankHistorySize to 50 without losing anything. I think the final solution for someone who needs 500+ yank history size is using nvim's async api too. I hope nvim optimizes vim language in an order that reading/loading/manipulating a list of 500 entries don't take that much time someday.

alok commented

I second doing this, or something else to cut the load time. Easyclip is almost 1/3 of my load time, and I have 178 (!) plugins.

@alok have you considered reducing g:EasyClipYankHistorySize?

alok commented

It's only 50. Would making it 0 bypass all the yank related code?
On Thu, Jun 30, 2016 at 5:38 PM Sassan Haradji notifications@github.com
wrote:

@alok https://github.com/Alok have you considered reducing
g:EasyClipYankHistorySize?


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#87 (comment),
or mute the thread
https://github.com/notifications/unsubscribe/AH8KTA27dGJeJIJNA741suEKrzEcU2isks5qRGGagaJpZM4INWRc
.

  • Alok

Do you have g:EasyClipShareYanks set to true?

alok commented

Yes
On Fri, Jul 1, 2016 at 3:58 AM Steve Vermeulen notifications@github.com
wrote:

Do you have g:EasyClipShareYanks set to true?


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#87 (comment),
or mute the thread
https://github.com/notifications/unsubscribe/AH8KTNqnOK9outfmLN4Xo6qoHbroX4wZks5qRPLEgaJpZM4INWRc
.

  • Alok

That is likely the reason why you have the lag. Can you try setting that to 0 and seeing if it is any faster?

The shared yanks functionality works by saving and reloading from file, so it can be slow. It would be nice to do that in a more lazy way if that is indeed the cause of the lag

alok commented

That made a big difference (~ 85 ms). If it was done lazily, I'd be pretty enthusiastic.