From 5cd5edc3bda54c5930031d7f5aaeab8b36325a5a Mon Sep 17 00:00:00 2001 From: Zaggy1024 Date: Wed, 12 Apr 2023 22:10:18 -0500 Subject: [PATCH] LibVideo/VP9: Copy data to reference frames row by row This changes the order of the loop copying data to a reference frame store so that it copies each row in a contiguous line rather than copying a column at a time, which caused unnecessary branches. This reduces the decode time on a fairly long 720p YouTube video by about 14.5% (~43.5s to ~37.2s). --- Userland/Libraries/LibVideo/VP9/Decoder.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/Userland/Libraries/LibVideo/VP9/Decoder.cpp b/Userland/Libraries/LibVideo/VP9/Decoder.cpp index e7167ac6c94..a3a6f476986 100644 --- a/Userland/Libraries/LibVideo/VP9/Decoder.cpp +++ b/Userland/Libraries/LibVideo/VP9/Decoder.cpp @@ -6,6 +6,7 @@ */ #include +#include #include #include @@ -1766,15 +1767,15 @@ DecoderErrorOr Decoder::update_reference_frames(FrameContext const& frame_ stride >>= frame_context.color_config.subsampling_x; } - auto original_buffer = get_output_buffer(plane); + auto const& original_buffer = get_output_buffer(plane); auto& frame_store_buffer = reference_frame.frame_planes[plane]; frame_store_buffer.resize_and_keep_capacity(width * height); + VERIFY(original_buffer.size() >= frame_store_buffer.size()); - for (auto x = 0u; x < width; x++) { - for (auto y = 0u; y < height; y++) { - auto sample = original_buffer[index_from_row_and_column(y, x, stride)]; - frame_store_buffer[index_from_row_and_column(y, x, width)] = sample; - } + for (auto y = 0u; y < height; y++) { + auto const* source = &original_buffer[index_from_row_and_column(y, 0, stride)]; + auto* destination = &frame_store_buffer[index_from_row_and_column(y, 0, width)]; + AK::TypedTransfer>::copy(destination, source, width); } } }