alexheretic / glyph-brush

Fast GPU cached text rendering
Apache License 2.0
673 stars 52 forks source link

`Section` and allocations #155

Open DavidVonDerau opened 1 year ago

DavidVonDerau commented 1 year ago

The glyph_brush API takes a Section to queue, but the Section internally uses a Vec to hold text. If I have a bunch of fields to write to the screen in different locations and with different bounds, it seems like each distinct field will force an allocation of a Vec with a capacity of 1.

I'm not sure if I'm using the API wrong, or if I've missed something.

If this is how the API works, would you be interested in a PR that changes Section to use a smallvec or other optimization for the scenario when a Section only hold a single string?

alexheretic commented 1 year ago

You are not mistaken. However, iirc my previous testing I would predict it not significant to the overall performance of drawing text (text layout, glyph rasterization, vertex generation & caching all being relatively much more expensive).

With that said if such changes would positively impact the benchmarks, or some new meaningful benchmark, it would be interesting and could point the way to better designs.

The other issue is changing away from Vec in Section would be breaking, something I'd probably avoid without big win.

You can run the existing benchmarks with, for example cargo bench --bench glyph_brush