Skip to content

perf: fn Rav1dFrameData::{seq,frame}_hdr: Remove .unwrap() and Arc::deref overhead #751

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

Open
kkysen opened this issue Feb 16, 2024 · 3 comments
Labels
low priority Issues that we would like to address at some point in the future performance

Comments

@kkysen
Copy link
Collaborator

kkysen commented Feb 16, 2024

I'm not a fan of these methods. They hide the cost of the .unwrap() and Arc derefs, which we really don't want to be doing in any tight loops like there might be in fn decode_b. Two solutions are:

  1. Most of the data accessed through things like frame_hdr are small Copyable fields. These we can just Copy out at the beginning and use directly. For larger fields like arrays, such as gmv, we can pay the cost there.

  2. Remove the frame_hdr and seq_hdr fields from Rav1dFrameData. If &Rav1dFrameData can be passed all the way down, then I think frame_hdr and seq_hdr can, and then we can do the .unwrap() and Arc deref only once at the beginning, and it very nicely untangles things.

See #748 (comment).

However, this is just for perf, and the solution is not exceedingly simple, so we can save it for later.

@randomPoison randomPoison added performance low priority Issues that we would like to address at some point in the future labels Mar 15, 2024
@jplatte
Copy link
Contributor

jplatte commented May 14, 2025

FWIW, there is ongoing work upstream to make Arc::deref zero-cost.

@kkysen
Copy link
Collaborator Author

kkysen commented May 14, 2025

FWIW, there is ongoing work upstream to make Arc::deref zero-cost.

Oh very neat, that looks promising.

@jplatte
Copy link
Contributor

jplatte commented May 25, 2025

Related: If Arc overhead is a concern, have you considered using triomphe? It contains an Arc type without a weak refcount (you don't seem to be using weak references), an OffsetArc type that AFAICT is the same thing as what std is transitioning to (which also looks very similar to your RawArc) + ArcBorrow which can also be interesting for improving perf though I haven't found any place in rav1d yet where it would be immediately applicable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
low priority Issues that we would like to address at some point in the future performance
Projects
None yet
Development

No branches or pull requests

3 participants