Closed gmorer closed 4 weeks ago
Thanks. I haven't been profiling allocations yet.
Unsure why there is specific code to owned it
I took this code from Smithay which needs to handle the generic runtime string case and didn't change it.
Need to do something with the Vec too. My idea was that cloning a render element like that should be cheap, but I forgot about this Vec in the shader.
Hello, i was checking the mem allocations. i noticed on using niri less than a minute a suprisingly high number caused by a clone in, the highest count of allocation around 70k (total, not size): https://github.com/YaLTeR/niri/blob/289ae3604d705cebc82cbcd23ee4534ded16d3af/src/layout/focus_ring.rs#L239
It clone a
BorderRenderElement
which clone aShaderRenderElement
which cloneVec<Uniform<'static>>
. The Uniform struct contain aname: Cow<'a, str>
.All the
name
given to theses Uniform are&static str
example: https://github.com/YaLTeR/niri/blob/289ae3604d705cebc82cbcd23ee4534ded16d3af/src/render_helpers/resize.rs#L92-L103So these cow should be Borrowed a not Owned.
Unsure why there is specific code to owned it, but making it a
Cow::Owned
will trigger a reallocation of the str.Stack trace of the allocations:
After the changes the allocation does not happen again.