memorysafety / memorysafety/rav1d

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

Open
#751 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

low priority performance
Dominant language
Assembly
Stars
643
Forks
81
PR merge metrics
No merged PRs in 30d

Description

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 https://github.com/memorysafety/rav1d/pull/748#discussion_r1491949073.

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading Rav1dFrameData and the fn decode_b call path, focusing on its frame_hdr and seq_hdr access. Compare the two proposed approaches in the issue and trace where &Rav1dFrameData can be passed further down. Done means the chosen design removes repeated unwrap and Arc dereference overhead from tight loops without changing decoding behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
backend, performance
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.