-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
struct MemPool
: Rewrite Rav1dMemPool
as fully safe and use it for…
… `Rav1dContext::picture_pool` (#1005) * Fixes #641. This rewrites from scratch the `unsafe` `Rav1dMemPool` as the safe `MemPool`. There are a few important differences here: * `Rav1dMemPool` used `Box<[u8]>` essentially. `MemPool` uses `Vec<T>` (`T = u8` in this case), which saves on some reallocations, as `Rav1dMemPool` would only reuse an allocation if it was exactly the same size. * By returning `Vec`s, the caller can decide how initialization is done, as `MemPool` only does the capacity allocation. Since these picture allocations are large, this code is performance-critical. When running on `./tests/large/chimera_10b_1080p.ivf -l 100`, I observed a ~5% performance regression initially (401 ms baseline, 415 ms new). However, if I do not zero out the data buffer (using `Vec::resize_with`, which only initializes the new elements from the previous use), then I observe a 5% performance improvement (376 ms). As I explain in a comment, I do `Vec::resize_with` in `cfg!(debug_assertions)`, but in release mode, I unsafely call `Vec::set_len`. The intermediate slices of the data that are materialized are technically UB, since the data is uninitialized. However, it should always be written to before read, and since this is so performance-critical, I think this is worth it. That said, sometimes the benchmarking seemed noisy, so someone else can take a look, too, if they'd like.
- Loading branch information
Showing
5 changed files
with
99 additions
and
156 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters