Question: which way is better for color animation?

Say I want to display a block of text where each character is displayed in different colors. And these colors change every 500ms.

If there are 7 colors in total, I can create 7 highlight groups (e.g. Color1, Color2 etc.) and apply those highlight groups on each characters.

Now there’re two way of doing this:

  1. After each 500ms link those highlight groups to some other highlight groups (e.g. GruvboxPurple, GruvboxBlue etc.). In this case, the highlight group applied to each character remains fixed.

  2. After each 500ms change the highlight group applied to each character. So the applied highlight groups keep changing.

I’m curious if one of those way is better than the other, or does it just depend on the situation at hand? Is there any performance implications?

I went with the first option in nvim-notify to implement the opacity effect. I can tell you that the performance shouldn’t be an issue, nvim-notify renders at ~60FPS with each frame updating the highlight groups (4 per notification) and I’ve never seen/heard of performance issues. Instinctively it seems like the better route to go as you’re not redefining extmarks (and whatever parsing etc you do) every render but I definitely don’t have any solid info there.

1 Like