charmbracelet / lipgloss

Style definitions for nice terminal layouts 👄
MIT License
7.87k stars 222 forks source link

New API: fast colors #81

Open antonmedv opened 2 years ago

antonmedv commented 2 years ago

Hi,

I'm building a new tool that requires a lot of Render calls (right now I prerender every line for a viewbox). The cpu profile shows lipgloss.Render func is taking lots of time:

Снимок экрана 2022-04-14 в 18 13 49

But I use only colors. Is it possible to add new methods, which allow to access only color functionality (no padding, borders, etc.)?

Thanks!

meowgorithm commented 2 years ago

That's a great idea; we can totally optimize for that. Probably better than adding a new method would be for Render to simply short circuit if the style only contains ANSI sequences (colors, bold, underline, etc).

meowgorithm commented 2 years ago

This could be further optimized, but what about something roughly like this: https://github.com/charmbracelet/lipgloss/commit/d92e7196bc88063dd54f230d59fd0000638e038e? This will effectively exit the render early if there are only text colors and text styles to render.

antonmedv commented 2 years ago

I can try check this branch.

antonmedv commented 2 years ago

Seems better, but still:

Снимок экрана 2022-04-14 в 23 17 56
meowgorithm commented 2 years ago

Yeah, it’s an improvement but we can do better. Have some ideas, will look into this some more.

muesli commented 2 years ago

If you really just need colors, you could of course try and see how you fare with directly using termenv here.