From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.ffmpeg.org (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTPS id 481594E639 for ; Thu, 26 Feb 2026 01:39:40 +0000 (UTC) Authentication-Results: ffbox; dkim=fail (body hash mismatch (got b'2STfQlIO5VFYUvkGz0OTPu8OJJ9zOZ4/52y6xhkqVz4=', expected b'g5L5yIg6wWW79Pn/DA9moHLkX8hNICk5DX2DH15mxCQ=')) header.d=ffmpeg.org header.i=@ffmpeg.org header.a=rsa-sha256 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ffmpeg.org; i=@ffmpeg.org; q=dns/txt; s=mail; t=1772069962; h=mime-version : to : date : message-id : reply-to : subject : list-id : list-archive : list-archive : list-help : list-owner : list-post : list-subscribe : list-unsubscribe : from : cc : content-type : content-transfer-encoding : from; bh=2STfQlIO5VFYUvkGz0OTPu8OJJ9zOZ4/52y6xhkqVz4=; b=xwQIuKWTg7Y/QE+0d141sY15gmw7iEMkdJiqocH790gff88R/yEC7HYVX5NdmYeonJ1MH UwLxOoKPo9oHRXjNh2Alj9too0iqHXqdcxiByFBcy7SjO7O8GdObXkuNOcXCeiMoUrCTWy5 yT7p6hQS5pjKbA88cbg1nakrpYBH7jTIPemOn/H4PJzLE0Ra1jzoYka0AUrBqIGC57N2EVg vCSh7WM2o/IBRpfdobWnCvUA+rDnpQMm+axUOIIce3FUT1+dS4a07cDJtErjhgZnW1hO0dV n7+ZRUQQFFMISnmPD+1eNSfV1glWJ6k+EjrkamjLm57jEZbg0GY0vy5fq5jA== Received: from [172.18.0.3] (unknown [172.18.0.3]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTP id 00D3769126E; Thu, 26 Feb 2026 03:39:22 +0200 (EET) ARC-Seal: i=1; cv=none; a=rsa-sha256; d=ffmpeg.org; s=arc; t=1772069945; b=auH2Aw81AhD3X1svEkbk3fyD8yt417ZSpu0Mt3CB9sOlej9ErySx8RGPsGw7WFE9ggGGR oq9z0iQwZV1UsRlkoBG2YJPBMUOyQZz8QEMyR9uhQT7QUoBb9q1TfT3Ic4fcT0s5Y0v4QHc FlgQH5Av4CNPcQCyOVIu/aOHam7Ja39vTjR8p5+cLz2uRYs+PR1UdnJewcMcZ4T3DVRRQZG DbDcXsdOFnAc4+942+H7CFba8Px9fAJiy5FmkSw2ck6450ZXTiVcp3IeLpdVHA5istPRhhE vipgJNmjjotNRQdq03NMhygzl/g3wFuSCz8zFtyvWRvjkaCK76YNCX2wQgaA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=ffmpeg.org; s=arc; t=1772069945; h=from : sender : reply-to : subject : date : message-id : to : cc : mime-version : content-type : content-transfer-encoding : content-id : content-description : resent-date : resent-from : resent-sender : resent-to : resent-cc : resent-message-id : in-reply-to : references : list-id : list-help : list-unsubscribe : list-subscribe : list-post : list-owner : list-archive; bh=bWLPMx3DL1gwqXM6RipcS8TV4+U3RyqRpgHqXQfUsB0=; b=fyNz1VmHSkP9wnLgunEnDFDu4YtCS+jxjyQiD8YJcE41+GC9BinBsX9ovyrw9t8G/cUBg dm4Wz0TSoEmZQTaWEy6oBMvX0IzZg4m+4DCiHdmaPId+UuoTCDbPIhvIOKquRU6462zBCWw WS7ZAuMeENnjHRJKqCGd4Df1ISAbpF29wGzFzI4djfzJsoKdoo6ZEmEvqm7h32i9ILttz32 gAWD2oxNoi0iiZSd8uhs7vIoIgA5tqg7J2CUt2FDYpcJkw3EAZe+pY7MLoEeQYMv5OtChC+ Ap/OhKvyLE3KRZx5x9/+KxtE0Z3qflsFCqRYNuGtV+3AzB9cM1BclU2R5pig== ARC-Authentication-Results: i=1; ffmpeg.org; dkim=pass header.d=ffmpeg.org header.i=@ffmpeg.org; arc=none; dmarc=pass header.from=ffmpeg.org policy.dmarc=quarantine Authentication-Results: ffmpeg.org; dkim=pass header.d=ffmpeg.org header.i=@ffmpeg.org; arc=none (Message is not ARC signed); dmarc=pass (Used From Domain Record) header.from=ffmpeg.org policy.dmarc=quarantine DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ffmpeg.org; i=@ffmpeg.org; q=dns/txt; s=mail; t=1772069937; h=content-type : mime-version : content-transfer-encoding : from : to : reply-to : subject : date : from; bh=g5L5yIg6wWW79Pn/DA9moHLkX8hNICk5DX2DH15mxCQ=; b=qvH+gnuA4M44DX9A3QVwyXZfvH6Jte7bETpixEh2d3K7+yDICTB05gSgzkzc6NtzI8YQ7 RshZirMHFvsV3mKe3wSFhCGnznG0quHSH1kLfAQ7xq4QSPg6Q6Zm8bhP4Y6U27ERUYglahG qxo+yE34NCfh6MIQxBslQ3CJehCAHg1F4xcJKrr482d9GQgi9ykBtPEFnFPdeLlnwRynN66 Xzp/cCrMuKStJGp1rk9w5RHv5pa35IQhRZyvF5MG5XOdOc6t+VqLv54Zaq9ZVxDbHOzHkea 20STJbP3Ucvfa1pvoOj5FpopgiD/hT9IUMmgDlygGYnuLHxerD49UiM5rhaA== MIME-Version: 1.0 To: ffmpeg-devel@ffmpeg.org Date: Thu, 26 Feb 2026 01:38:57 -0000 Message-ID: <177206993770.25.12338904471516808009@29965ddac10e> Message-ID-Hash: Q74OCFUBFSDRBMKW5JBI3NYQSTNFUKBO X-Message-ID-Hash: Q74OCFUBFSDRBMKW5JBI3NYQSTNFUKBO X-MailFrom: code@ffmpeg.org X-Mailman-Rule-Hits: nonmember-moderation X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; header-match-ffmpeg-devel.ffmpeg.org-0; header-match-ffmpeg-devel.ffmpeg.org-1; header-match-ffmpeg-devel.ffmpeg.org-2; header-match-ffmpeg-devel.ffmpeg.org-3; emergency; member-moderation X-Mailman-Version: 3.3.10 Precedence: list Reply-To: FFmpeg development discussions and patches Subject: [FFmpeg-devel] [PR] avcodec/notchlc: lz4_decompress() avoid byte loops, try to work in blocks (PR #22287) List-Id: FFmpeg development discussions and patches Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: michaelni via ffmpeg-devel Cc: michaelni Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Archived-At: List-Archive: List-Post: PR #22287 opened by michaelni URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/22287 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/22287.patch 47720380 decicycles -> 34335598 decicycles >>From b14a62a84da87062bf9a1c63e06773b819cbf7b4 Mon Sep 17 00:00:00 2001 From: Michael Niedermayer Date: Wed, 25 Feb 2026 16:57:01 +0100 Subject: [PATCH 1/2] avcodec/notchlc: Avoid clearing history in lz4_decompress() instead of clearing history before "byte 0", we error out clearing 64kb takes time, which this commit avoids Benchmark with big_buck_bunny\ NotchLC\ Optimal\ Encoding\ 1920.mov shows no meassurable difference though Signed-off-by: Michael Niedermayer --- libavcodec/notchlc.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/libavcodec/notchlc.c b/libavcodec/notchlc.c index c28fddcea0..278499f450 100644 --- a/libavcodec/notchlc.c +++ b/libavcodec/notchlc.c @@ -79,8 +79,9 @@ static int lz4_decompress(AVCodecContext *avctx, PutByteContext *pb) { unsigned reference_pos, delta, pos = 0; - uint8_t history[HISTORY_SIZE] = { 0 }; + uint8_t history[HISTORY_SIZE]; int match_length; + int wraped = 0; while (bytestream2_get_bytes_left(gb) > 0) { uint8_t token = bytestream2_get_byte(gb); @@ -106,6 +107,7 @@ static int lz4_decompress(AVCodecContext *avctx, if (pos == HISTORY_SIZE) { bytestream2_put_buffer(pb, history, HISTORY_SIZE); pos = 0; + wraped = 1; } } } @@ -125,7 +127,13 @@ static int lz4_decompress(AVCodecContext *avctx, match_length += current; } while (current == 255); } - reference_pos = (pos >= delta) ? (pos - delta) : (HISTORY_SIZE + pos - delta); + reference_pos = pos - delta; + if (pos < delta) { + if (!wraped) + return AVERROR_INVALIDDATA; + reference_pos += HISTORY_SIZE; + } + if (pos + match_length < HISTORY_SIZE && reference_pos + match_length < HISTORY_SIZE) { if (pos >= reference_pos + match_length || reference_pos >= pos + match_length) { memcpy(history + pos, history + reference_pos, match_length); @@ -140,6 +148,7 @@ static int lz4_decompress(AVCodecContext *avctx, if (pos == HISTORY_SIZE) { bytestream2_put_buffer(pb, history, HISTORY_SIZE); pos = 0; + wraped = 1; } reference_pos %= HISTORY_SIZE; } -- 2.52.0 >>From b889dbc8dc1451b75e4db67c3c3bd7d4eef7e067 Mon Sep 17 00:00:00 2001 From: Michael Niedermayer Date: Wed, 25 Feb 2026 17:47:11 +0100 Subject: [PATCH 2/2] avcodec/notchlc: lz4_decompress() avoid byte loops, try to work in blocks 47720380 decicycles -> 34335598 decicycles --- libavcodec/notchlc.c | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/libavcodec/notchlc.c b/libavcodec/notchlc.c index 278499f450..079e821d6c 100644 --- a/libavcodec/notchlc.c +++ b/libavcodec/notchlc.c @@ -98,18 +98,16 @@ static int lz4_decompress(AVCodecContext *avctx, if (bytestream2_get_bytes_left(gb) < num_literals) return AVERROR_INVALIDDATA; - if (pos + num_literals < HISTORY_SIZE) { - bytestream2_get_buffer(gb, history + pos, num_literals); - pos += num_literals; - } else { - while (num_literals-- > 0) { - history[pos++] = bytestream2_get_byte(gb); - if (pos == HISTORY_SIZE) { - bytestream2_put_buffer(pb, history, HISTORY_SIZE); - pos = 0; - wraped = 1; - } + while (num_literals) { + int max_literals = FFMIN(num_literals, HISTORY_SIZE - pos); + bytestream2_get_buffer(gb, history + pos, max_literals); + pos += max_literals; + if (pos == HISTORY_SIZE) { + bytestream2_put_buffer(pb, history, HISTORY_SIZE); + pos = 0; + wraped = 1; } + num_literals -= max_literals; } if (bytestream2_get_bytes_left(gb) <= 0) @@ -134,24 +132,26 @@ static int lz4_decompress(AVCodecContext *avctx, reference_pos += HISTORY_SIZE; } - if (pos + match_length < HISTORY_SIZE && reference_pos + match_length < HISTORY_SIZE) { - if (pos >= reference_pos + match_length || reference_pos >= pos + match_length) { - memcpy(history + pos, history + reference_pos, match_length); - pos += match_length; + while (match_length) { + int max_match; + if (reference_pos > pos) { + max_match = FFMIN(match_length, HISTORY_SIZE - reference_pos); + memmove(history + pos, history + reference_pos, max_match); + pos += max_match; + reference_pos += max_match; + if (reference_pos == HISTORY_SIZE) reference_pos = 0; } else { - while (match_length-- > 0) - history[pos++] = history[reference_pos++]; - } - } else { - while (match_length-- > 0) { - history[pos++] = history[reference_pos++]; + max_match = FFMIN(match_length, HISTORY_SIZE - pos); + av_memcpy_backptr(history + pos, pos - reference_pos, max_match); + pos += max_match; + reference_pos += max_match; if (pos == HISTORY_SIZE) { bytestream2_put_buffer(pb, history, HISTORY_SIZE); pos = 0; wraped = 1; } - reference_pos %= HISTORY_SIZE; } + match_length -= max_match; } } -- 2.52.0 _______________________________________________ ffmpeg-devel mailing list -- ffmpeg-devel@ffmpeg.org To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org