Hi Hari,

On 5/13/06, Yegappan Lakshmanan <[EMAIL PROTECTED]> wrote:
Hi Hari,

On 5/12/06, Hari Krishna Dara <[EMAIL PROTECTED]> wrote:
>
> I am finding that the new taglist() function performans much slower than
> the :tag command for the same pattern. I have a couple of huge tag
> files in 'tags' and doing something like:
>
> :ta /.*t<Tab>
>
> will start giving me the matches with in a second or two (at the most),


When you try to list all the matching tags using the above command,
you will notice that it doesn't list all the matching tags. It will list
only the first few matching tags.

- Yegappan


> but calling taglist('t') will take a long time (didn't finish after
> waiting for a couple of minutes). I would imagine both :tag command and
> taglist() using the same tag lookup code, so probably it is the
> generation of list of dictionary entries that is very inefficient.
>

When you use the ":tag <pattern>" command, only the next few
matching tags are retrieved from the tags file. OTOH, the taglist()
function retrieves all the matching tag names from the tags file.

The dictionary creation is not slowing down the taglist() function.
Searching the entire tags file for all the matching tag names is
slowing down the taglist() function.

> To test this theory, in a crude way, I tried:
>
> :echo len(taglist('z'))
>
> And I got 5427 as the response in a couple of seconds, so the match for
> 't' must have been a lot more, resulting in a lot more time taken.
>
> On a smaller tags file of containing only about 40,000 tags (about 4mb),
> for pattern 't', I got a match of 34361 entries, but it took about
> 10seconds to complete, but if I use the :tag command the response is
> almost instantaneous.
>
> On further study, I realized that the :tag command with pattern comes
> back with matches very fast, but the same with :ts is very slow, so
> something like:
>
> :ts /.*t<CR>
>
> will take a long time to come up with the list. I don't know if this is
>

The tselect, tjump, tlast and ltag commands also load all the matching
tags from the tags file. These commands are similar to the taglist()
function, so these commands also will take similar amount of time
to get all the matching tag names from the tags file.

>
> because Vim is trying to create a buffer containing all the entries for
> presentation purposes, for the same reasons taglist() is also slow. In
> any case, if creating such a huge list of dictionary items is going to
> be so time consuming (and memory intensive), how about supporting a
> second argument for passing an index? In this case, the script can
> restrict it to always say, only the first 100 entries (or whatever is
> configured by the user). I would assume that there are optimizations for
> fast lookup of the same pattern (the way :ts command performs in
> subsequent invocations), if you have to call the function 100 times.
>

We can modify the taglist() function to take a starting index and the
number of tags to return:

     taglist(<pattern>, <start_idx>, <count>)

If you want all the matching tags, then you can use

    taglist(<pattern>, 0, 9999999)

Note that it will not be possible to get a list of all the matching tags
and the number of matching tags without parsing the entire tags file.

- Yegappan

Reply via email to