Replies: 1 comment 2 replies
-
Since a recent refactor of how and when text is laid out, it should be possible to remove the need for |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I noticed that most widgets that render text also own a copy of the
String
. This was a bit alarming due to the nature of immediate-mode GUI designs. For instance creating aLabel
with a&'static str
has no reason to clone and take ownership of this string, given theLabel
only lives long enough to create a few paint operations. The deeper I dug, the more I saw this pattern used. TheFont
structs also take ownership of aString
and so forth.#302 really lead me further down this rabbit hole. And though I kind of like the added ergonomics of creating a
Label
et al. from a number orBox<dyn Error>
, I'm still concerned about the cost of cloning strings.To begin quantifying that cost, I created a copy-pasta duplicate of the
Label
struct and cleverly named itCowLabel<'a>
, owning aCow<'a, str>
instead ofString
. The constructor avoids cloning quite simply:... along with the usual
From<T>
impls and a convenience method onUi
. Then some new benchmarks:Here are my results in comparison to
Label
:This is far from scientific and of course it doesn't go any further on optimizations or attempt to remove other clones for
Galley
orFont
or any of these underlying layers. But it does show a modest improvement for both borrowed and owned strings.Thoughts and opinions?
Beta Was this translation helpful? Give feedback.
All reactions