Giter VIP home page Giter VIP logo

Comments (26)

MacDragon avatar MacDragon commented on July 25, 2024 1

My hack was entirely containing cache lookup to a small internally held table, no hash lookups - so I can't comment how much faster or slower it is compared to cache system lookup call, and would only probably be viable for a reasonably small latin like glyph set, the ttf fonts we're using have < 200 glyphs included after being stripped for size, so a lookup table seemed reasonable compromise for quickness of implementation, and for at least one busy text screen ( several hundred chars ), my whole lvgl rendering cycle appeared to go from 280ms to 8ms

from lvgl.

MacDragon avatar MacDragon commented on July 25, 2024

I can confirm it really really hurts current performance, I've not had time to go back and try to do a 'real' cache implementation, but I quickly hacked a sufficient array table based one for our font usage into project and it increased performance well over an order of magnitude for a busy text screen. The quick hack I did was mentioned in one of the lvgl 9 closed cache threads the other day ( #4835 ), and a suggestion was given there to use details from freetype implementation into tiny ttf to properly use the inbuilt cache routines for the cache. I may go back to this later once current critical phase of project is done, but for now it works well enough for us that I don't have time. I did also add a table clear if font size is chanced in addition to the mentioned there, but our solution is not suitable as a library pull for sure.

from lvgl.

codewitch-honey-crisis avatar codewitch-honey-crisis commented on July 25, 2024

Thanks for you feedback. I'm the original contributor of this library which I adapted from some public domain code for game engines :), and I implemented the cache quickly as it was a requirement for LVGL. I need to do some legwork if I was to upgrade this code, because I do not yet fully understand the LVGL cache system yet. I learned just enough of it to be dangerous.

from lvgl.

MacDragon avatar MacDragon commented on July 25, 2024

With the additional quick 'n dirty cacheing in place, it now works pretty well for us, difference in speed vs plain bitmap fonts is negligible now, at least in environment with plenty enough RAM to cache everything - I did also increase the max amount of elements allowed into the cache quite a bit, though I haven't tried to verify how much difference that made.

from lvgl.

codewitch-honey-crisis avatar codewitch-honey-crisis commented on July 25, 2024

I appreciate this. It's all very helpful. I'll tinker with the caching once I solve some unrelated issues I'm having with the new LVGL 9+

from lvgl.

codewitch-honey-crisis avatar codewitch-honey-crisis commented on July 25, 2024

Actually Gabor, I found it now. I just had to look further in the source than I was looking. Thanks anyway.

@kisvegabor can I get some guidance on using the cache? I'm not clear on how the search key is used below:

const lv_font_t * font = g_dsc->resolved_font;
tiny_ttf_cache_data_t search_key = {
    .font = (lv_font_t *)font,
    .unicode = unicode_letter,
    .size = font->line_height,
    //.glyph_index
    //.draw_buf
};

I've added glyph_index. Like draw_buf it's to be fetched FROM the cache, not used to search for the data. Does that make sense? How does lv_cache_acquire_or_create(tiny_ttf_cache, &search_key, (void *)font->dsc); know to leave draw_buf out of the search criteria? I need the same for glyph_index.

from lvgl.

codewitch-honey-crisis avatar codewitch-honey-crisis commented on July 25, 2024

I tried caching the glyph indices but it turns out the LVGL cache system is slower than stbtt_FindGlyphIndex. In any case, the latest bits are much faster than 9.1 release so I'm happy.

from lvgl.

W-Mai avatar W-Mai commented on July 25, 2024

I tried caching the glyph indices but it turns out the LVGL cache system is slower than stbtt_FindGlyphIndex. In any case, the latest bits are much faster than 9.1 release so I'm happy.

So, is there no longer a need to add a cache for glyph index?

But @MacDragon said that the performance has improved a lot.

from lvgl.

codewitch-honey-crisis avatar codewitch-honey-crisis commented on July 25, 2024

@MacDragon which version of LVGL?

from lvgl.

MacDragon avatar MacDragon commented on July 25, 2024

9.1

from lvgl.

codewitch-honey-crisis avatar codewitch-honey-crisis commented on July 25, 2024

The latest bits in the master branch are much faster, in my experience. After looking at it, someone changed the cache code to eliminate the call to FindGlyphIndex inside the rendering routine. That improved performance pretty dramatically.

from lvgl.

MacDragon avatar MacDragon commented on July 25, 2024

Interesting, preferences is generally to stick on a 'release' version, so haven't tried raw master branch.

from lvgl.

codewitch-honey-crisis avatar codewitch-honey-crisis commented on July 25, 2024

I totally get it. I'm just putting it out there so you know once the next version is rolled out, those perf improvements have been made. :)

from lvgl.

MacDragon avatar MacDragon commented on July 25, 2024

Good to know certainly, will bear in mind whenever next release is.

from lvgl.

W-Mai avatar W-Mai commented on July 25, 2024

The latest bits in the master branch are much faster, in my experience. After looking at it, someone changed the cache code to eliminate the call to FindGlyphIndex inside the rendering routine. That improved performance pretty dramatically.

Wow, that sounds great. Could you please tell me where this code is?

from lvgl.

codewitch-honey-crisis avatar codewitch-honey-crisis commented on July 25, 2024

src/libs/tiny_ttf/tiny_ttf.c (give or take, it's from memory)

I'm not sure it can be retrofitted to earlier versions, as I am half sure the generalized caching system has evolved since 9.1

from lvgl.

W-Mai avatar W-Mai commented on July 25, 2024

src/libs/tiny_ttf/tiny_ttf.c (give or take, it's from memory)

I'm not sure it can be retrofitted to earlier versions, as I am half sure the generalized caching system has evolved since 9.1

OK fine

As far as the information I know now is concerned, tiny_ttf adds the cache generated by bitmap.

Generally speaking, what we are looking forward to is

  1. unicode -> glyph_index
  2. glyph_index -> bitmap

Two-level cache, but at present, there is only glyph_index -> bitmap cache now.

@MacDragon describes the addition of a glyph_index cache.

I don't seem to find this related cache.

By the way, it's I modified the cache of bitmap, so I'm quite concerned about this issue. 😁

from lvgl.

W-Mai avatar W-Mai commented on July 25, 2024

I want to confirm that if some optimizations have been made on the tiny_ttf library itself, resulting in the acceleration of GetGlyphIndex, then I don't need to modify it further.

If not, I can add the cache of unicode -> glyph_index.

from lvgl.

codewitch-honey-crisis avatar codewitch-honey-crisis commented on July 25, 2024

There isn't a two level cache. The reason being is I tried implementing a two level cache using the generalized caching system. My tests found that stbtt_FindGlyphIndex is usually or always faster than a cache lookup. Now, when caching entire renders as bitmaps, it pays for itself, but just caching letters->glyph_indexes for a font does not.

It may be possible to do what MacDragon is doing and implement your own cache. I've decided not to do that after considering it because the renders are already quite quick now that the bitmap cache also caches the glyph_index, coupled with the fact that going "off book" and sidestepping LVGL's cache and its management infrastructure left a bad taste in my mouth. It would require at best, a whole separate set of config #defines just to hammer out how much cache to give it. And that's best case scenario, and not accounting for the added flash footprint, maintenance, and testing. It just doesn't seem worth it given current performance. Have you tried the latest bits?

from lvgl.

MacDragon avatar MacDragon commented on July 25, 2024

Yes, I did note in my post in other thread about the hacky implementation that I wouldn't consider something like it for a pull either, it as mostly noting that there was maybe potential, but if how labels are rendered has changed it may be less necessary.

from lvgl.

codewitch-honey-crisis avatar codewitch-honey-crisis commented on July 25, 2024

After what I tried, I'm thinking that too. Your "hacky" implementation is probably faster than the generalized cache, but the extra churn in maintaining a separate cache (in terms of runtime overhead, extra complication of config, flash space and labor) is simply not worth it I think. It's quite fast now in my tests. I think in general it's a great idea to find out if you need to optimize before you optimize, which is why I asked W-Mai about trying the latest bits.

from lvgl.

codewitch-honey-crisis avatar codewitch-honey-crisis commented on July 25, 2024

You know what would be interesting? If LVGL cached the actual metrics fetching call results of any and all fonts, instead of calling the metrics callback over and over. Caching the width, height and advance by unicode letter and font. I'd have to remove the set_font_size call in tiny ttf because it would break the cache, but in general it might sidestep this issue, and pay for itself. @kisvegabor , your thoughts on this?

ETA: I'm off to bed for now. I'll pick this back up where we left off when I can.

from lvgl.

W-Mai avatar W-Mai commented on July 25, 2024

@codewitch-honey-crisis You can take a look on the implementation of lv_freetype. In the implementation of freetype, the use of cache is very suitable, using two-level cache, which improves a lot of efficiency.

from lvgl.

codewitch-honey-crisis avatar codewitch-honey-crisis commented on July 25, 2024

freetype also takes gobs of ram. TinyTTF doesn't, which is kind of the point of it,

from lvgl.

codewitch-honey-crisis avatar codewitch-honey-crisis commented on July 25, 2024

Did you even use the latest bits? I'm not putting in two-level cache.

from lvgl.

W-Mai avatar W-Mai commented on July 25, 2024

Did you even use the latest bits? I'm not putting in two-level cache.

I know that, that's what I wrote, the draw_buf cache, lying in the latest bits.

But I think we can add a new unicode -> glyph_dsc will speed up the process.

Please take a look at, here is the code what I'm mentioned 😁

from lvgl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.