Skip to content

Commit 0e2c74c

Browse files
maj160shssoichiro
authored andcommitted
Use chunks_exact for performance in diff method
This is part of a series of commits authored by @maj160 to improve performance of rav1e. This commit results in an overall performance improvement of about 2% at speed 2 10-bit: ``` Benchmark 1: ~/Downloads/rav1e_master -s 2 --quantizer 64 ~/xiph-media-files/objective-1-fast-10bit/speed_bag_640x360_60f.y4m -y -o /dev/null Time (mean ± σ): 43.695 s ± 0.151 s [User: 43.684 s, System: 0.180 s] Range (min … max): 43.518 s … 44.033 s 10 runs Benchmark 2: ~/Downloads/rav1e_mod -s 2 --quantizer 64 ~/xiph-media-files/objective-1-fast-10bit/speed_bag_640x360_60f.y4m -y -o /dev/null Time (mean ± σ): 42.808 s ± 0.081 s [User: 42.828 s, System: 0.170 s] Range (min … max): 42.702 s … 42.961 s 10 runs ```
1 parent db7ff31 commit 0e2c74c

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/encoder.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -1358,11 +1358,11 @@ fn write_key_frame_obus<T: Pixel>(
13581358
/// Write into `dst` the difference between the blocks at `src1` and `src2`
13591359
fn diff<T: Pixel>(
13601360
dst: &mut [i16], src1: &PlaneRegion<'_, T>, src2: &PlaneRegion<'_, T>,
1361-
width: usize, height: usize,
13621361
) {
1362+
debug_assert!(dst.len() % src1.rect().width == 0);
1363+
13631364
for ((l, s1), s2) in dst
1364-
.chunks_mut(width)
1365-
.take(height)
1365+
.chunks_exact_mut(src1.rect().width)
13661366
.zip(src1.rows_iter())
13671367
.zip(src2.rows_iter())
13681368
{
@@ -1424,7 +1424,11 @@ pub fn encode_tx_block<T: Pixel, W: Writer>(
14241424
) -> (bool, ScaledDistortion) {
14251425
let PlaneConfig { xdec, ydec, .. } = ts.input.planes[p].cfg;
14261426
let tile_rect = ts.tile_rect().decimated(xdec, ydec);
1427-
let area = Area::BlockStartingAt { bo: tx_bo.0 };
1427+
let area = Area::BlockRect {
1428+
bo: tx_bo.0,
1429+
width: tx_size.width(),
1430+
height: tx_size.height(),
1431+
};
14281432

14291433
if tx_bo.0.x >= ts.mi_width || tx_bo.0.y >= ts.mi_height {
14301434
return (false, ScaledDistortion::zero());
@@ -1526,8 +1530,6 @@ pub fn encode_tx_block<T: Pixel, W: Writer>(
15261530
residual,
15271531
&ts.input_tile.planes[p].subregion(area),
15281532
&rec.subregion(area),
1529-
tx_size.width(),
1530-
tx_size.height(),
15311533
);
15321534
} else {
15331535
residual.fill(0);

0 commit comments

Comments
 (0)