> Personally, I haven't measured a significant difference between prop_add() 
> and prop_add_list() for normal text-properties. For signs, on the
> other hand, there's a significant difference between sign_place() in a
> for-loop and sign_place_list().
> 
> But what I've noticed is that calling prop_remove() can be very slow when
> removing over a thousand virtual text-properties.
> 
> For comparison: with normal text-properties, we can group them under a given
> text-prop ID and use that ID in prop_remove() to remove a set of "related"
> text-properties:
> 
> prop_remove({
>     'id': group_id,
>     'bufnr': some_bufnr,
>     'type': 'my_prop_type',
>     'both': true,
>     'all': true
> })
> 
> This is very efficient, even when removing 10'000 text-properties with
> the same ID.
> 
> However, with virtual text-properties we cannot group them under the same ID
> (why?),

The text of the virtual text property is stored in an array, the ID is
used to lookup the text, thus it has to be unique.

> instead each virtual text will be assigned a unique ID. Thus, we need
> to cache every ID returned by prop_add() and then remove them
> individually in a for-loop, something like:
> 
> var virt_IDs: list<number>
> # fill virt_IDs with IDs returned by prop_add() …
> 
> for i in virt_IDs
>     prop_remove({
>         'id': i,
>         'bufnr': some_bufnr
>     })
> endfor
> 
> Since the IDs are unique within a buffer, we don't have to specify
> `type` or `both` in `prop_remove()`. Nevertheless, removing virtual
> text this way is very slow when several hundred properties need to be
> removed.
>
> To give you an example, on my 10 year old laptop calling prop_remove() in a
> for-loop to remove 10'000 text-properties takes over 2 seconds. If I remove 
> the 'id' entry in prop_remove() and match by 'type' it takes only a
> few milliseconds. It's also significantly faster when I add 'lnum' to
> prop_remove(), but the problem is that lnum isn't known when removing
> the virtual-text since the lines might have shifted.

Can you not delete all properties with a given type?  Considering that
defining a type is not much work, you could use the type to group
properties together.  You can define different type names with the same
highlighting.  The only condition is that you know beforehand which
virtual text properties you want to remove at the same time.

> I think removing a set of virtual text-properties is very common, for
> example, when `align`, `wrap` or `text_padding_left` need to be
> toggled. The only way to accomplish this is by removing the old ones
> and re-adding them with a different 'align', 'wrap' etc. value.

-- 
In Joseph Heller's novel "Catch-22", the main character tries to get out of a
war by proving he is crazy.  But the mere fact he wants to get out of the war
only shows he isn't crazy -- creating the original "Catch-22".

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///                                                                      \\\
\\\        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
-- 
You received this message from the "vim_dev" 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_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/20221128165020.E9A431C0A61%40moolenaar.net.

Raspunde prin e-mail lui