Implement Deref(Mut) on BufferVec/UniformVec#3532
Implement Deref(Mut) on BufferVec/UniformVec#3532james7132 wants to merge 15 commits intobevyengine:mainfrom
Conversation
|
Added UniformVec to this as well. (Couldn't find a good way to handle DynamicUniformVec). |
2c7d7db to
b2b7a5d
Compare
|
I’ll do a full review in a bit but capacity can also be removed in my opinion. In reserve we can just use size > self.scratch.len() and otherwise capacity is just self.values.len(). |
superdump
left a comment
There was a problem hiding this comment.
I made a few suggestions for what I think are improvements.
I see what you mean about implementing Deref and DerefMut on DynamicUniformVec. It looks to me like it could be done, but the user needs to know they need to wrap their T in DynamicUniform. I would argue that we should just do that for consistency and deref through to the UniformVec's internal Vec<DynamicUniform<T>>. What do you think?
I went ahead and did it, though I'm not a fan of exposing the need for users to wrap it themselves, seems like a regression in API design. However, it's probably for the best in terms of consistency here. |
|
Also note the failing docs check. |
|
@james7132 could you update this on top of main ready for tomorrow’s round of reviews by Cart? |
|
bors try |
tryBuild failed: |
|
@cart on #4079 for storage buffers you didn’t want to use deref and derefmut, and instead have accessors so I added .values() and .values_mut(). What do you want to do with this PR/with *UniformVec and BufferVec? They are specifically Vec-like but I think the goal is to expose the internal Vec of values to allow use of all Vec APIs for optimisation purposes. That could be achieved by either deref impls or accessors. |
|
My biggest reservation about this is that it is basically saying "vec is our public interface, forever". It is committing to never syncing any internal state between the backing Vec and other fields on UniformVec. For example, maybe in the future we decide we want to preserve data across frames and track what needs to be updated internally. That should probably be a new abstraction, but the point is, exposing the vec internals eliminates all forms of internal state tracking. Likewise, it means we can't choose to abstract out things like the |
Should we close this then? |
|
Barring further discussion on the matter (I'm open to having my mind changed), then yeah I think we should close this. |
This PR fixes #3531, and is required by #3504 to improve rendering performance and readability.
Objective
VecAPI for more efficiently handling larger mutations to the underlyingVec.Solution
DerefandDerefMutonBufferVec, targeting the underlyingVecreservefunction and renamed toreserve_buffersince it only really needs to run before queuing a write to the buffer.BufferVecfunctions (is_empty,len,clear, etc), which are now exposed viaDeref(Mut).capacitytobuffer_capacityto avoid clashing with theDeref'ed capacity fromVec.item_sizefield from the type as it is run-time constant for the type.