New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is it possible to replace MediaSourceStream
with generic M: MediaSource
?
#171
Comments
I think this is a topic that could go very deep, but... The short answer is that from my experience, I don't think there will be much of a gain in performance. Nothing measurable at least. Memory copies are extremely fast and optimized, and we are only copying tens of MB of memory. Removing a single branch from a The long answer is that it's a complicated problem...
The motivation behind making If we made everything that used
There are basically no cases where none of these features are used, so even if we went with the buffered wrapper approach, the benefits would be lost since everything would use the buffered wrapper. Therefore, to see any advantages, |
To my understanding, adding generics shouldn't bring much more complication except for propagating the type parameters since the same methods are gonna be called; there should be almost no change to the actual logic (but I may be wrong). In my opinion, the principle of pay-for-only-what-you-use is just too attractive and aligned-to-Rust to pass up. In a sense, this is "free" performance that users at a higher level have to leave on the table because the choice had been made for them, even though they might have been in a better position to make the call themselves. |
For the most part, yeah. Thinking about this further, the probable way forward would be to make The existing
The drawback of course would be the complexity of new I think one application where this could yield a theoretical benefit is network streaming. Presumably instead of copying newly received data into a buffer the preexisting buffers could be used, but I'm not entirely sure if that's reasonable. Would love to hear others' opinions on this. |
i think relevant to this issue would be #260, i ended up doing a buffer before |
Instead of taking in
MediaSourceStream
, is it possible to have decoders generically take in aM: MediaSource
trait instead? (Or possiblyBox<dyn MediaSource>
, although I prefer the generic version because of fewer pointer indirections). The reason being, the underlyingMediaSource
implementation may already be buffered or is entirely in-memory, causing unnecessary copy into the buffer withinMediaSourceStream
.The existing
MediaSourceStream
can be repurposed asMediaSourceStream<M>
, a buffered wrapper type overMediaSource
types, so that the user can decide for themselves whether they require buffering (pay only when needed).The text was updated successfully, but these errors were encountered: