Repository navigation
perf(obs-filters): skip log10f/powf below threshold in compressor, limiter and expander (#3190) - #3229
Merged
Conversation
zackees
enabled auto-merge
October 31, 2026 18:08
Member
Author
|
Handed off to the coordinator. Lint passes locally and the new test passes on both the old and new code (I built it outside CMake, with stubs for libobs). I didn't run the local-gate stamp, so PR CI runs Tier 2. |
zackees
force-pushed
the
perf/3190-dynamics-threshold
branch
from
October 31, 2026 18:19
1afdd97 to
a9cb538
Compare
zackees
commented
Oct 31, 2026
zackees
left a comment
Member
Author
There was a problem hiding this comment.
Coordinator review: No blocking findings.
- The skip is output-only. In the compressor and limiter,
process_compression/limiter_process_compression(compressor-filter.c.h:350,limiter-filter.c.h:149) only scale samples. The envelope is computed earlier inanalyze_envelope/analyze_sidechainand is not touched. For envelopes underdb_to_mul(threshold)*0.9999,slope*(threshold-env_db)is positive, so the old path gave exactlydb_to_mul(0)=1. NaN and 0 envelopes still take the exact path (!(x < t)), or give 1 as before. - Expander (
expander-filter.c.h:362):gain_db[idx](the attack/release state) is still written before the changed line. Only the output multiplier is short-circuited.x < 0 ? db_to_mul(x) : 1equalsdb_to_mul(fminf(0,x)), including NaN. The upward-compressor branch is unchanged. test/cmocka/test_dynamics_threshold.ccompares the real stages bit for bit against the original formula, including the threshold neighbours and the margin edge. The test is new and edits no existing C test. Characterization instead of RED is fine for a perf change that preserves behaviour.
zackees
commented
Oct 31, 2026
zackees
left a comment
Member
Author
There was a problem hiding this comment.
Coordinator follow-up: #3190 now accepts epsilon differences (relative error ≤ 1e-6, see the Decided: comment there). That allows a faster design than the skip. The skip only helps below the threshold, and in a microbenchmark it was no faster at -6 dBFS (15.4 vs 14.6 ns/sample).
Suggested changes:
limiter-filter.c.h:gain = e > t ? t / e : 1.0f, witht = db_to_mul(cd->threshold)stored inlimiter_update. Measured about 15× faster while limiting.compressor-filter.c.h:gain = e > t ? powf(t / e, cd->slope) : 1.0f. Measured about 2× faster while compressing, max relative error 2.5e-7.expander-filter.c.h: keep your skip, and replacelog10f/powfwithlog2f/exp2fand the constant 6.0206. The dB-domain smoothing stays.- Drop the
0.9999fmargin and compare with an exacte > t. - In
test_dynamics_threshold.c, change the comparison from bit-for-bit to a relative tolerance of 1e-6. Keep the 0 and NaN envelope cases: both still give gain 1.
The issue still requires port_comparison before/after numbers at -40, -20 and mixed levels in the PR body.
This was referenced Oct 31, 2026
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
The compressor, limiter and expander called
log10fandpowfon every sample, even when the result was exactly 1.fminf(0, slope * (threshold - env_db))is 0, so the gain isdb_to_mul(0) = 1. Each call now computesdb_to_mul(threshold) * 0.9999fonce and skips both libm calls for envelopes under it. The 1e-4 margin (about 0.0009 dB) is far larger thanlog10f's rounding error, so an envelope near the threshold still takes the exact path.powfwhengain_db >= 0(including NaN), becausedb_to_mul(fminf(0, x))is exactly 1 there.Output is bit-identical. No public header, C test or
audio-math.hchanged.Commits
test/cmocka/test_dynamics_threshold.c. It compares all three gain stages bit for bit with the original formula: 1,507,328 checks across thresholds from -60 to 0 dB, ratios from 1 to 32, envelopes from -140 to +6 dB, a dense sweep within ±0.01 dB of the threshold, the exact threshold and its float neighbours, and silence. It passes on master, as a characterization test should (there is no bug to show RED).checks=1507328 failures=0, before and after.Measurements
Per audio tick (1024 frames, stereo). Median of 7 runs × 20,000 iterations, gcc 15.2
-O2, pinned to one core of a Ryzen 7 3700X, two alternating old/new runs. The harness is a standalone C file that includes the three filter sources, so it times exactly the shipped code. It is not committed, because there is no C filter bench inrecord.py.Most audio sits under a compressor's or limiter's threshold most of the time, so the common case is the 8x row.
Tiers
Test cost: one C test, about 1.5 M float comparisons, well under 1 s. It starts no threads.
Fixes #3190. Refs #3176.