From e59bcdbb986bb4bcf167a8a74db7788b9bed08ce Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Wed, 30 Sep 2026 20:57:10 +0200 Subject: [PATCH] Optimize: Evaluate built-in LUT generator once per entry The same value was computed three times. Time constructing processors for all displays/views/spaces in the ACES studio config goes from 279ms to 223ms on Apple M3 Max. Signed-off-by: Brecht Van Lommel --- src/OpenColorIO/transforms/builtins/OpHelpers.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/OpenColorIO/transforms/builtins/OpHelpers.cpp b/src/OpenColorIO/transforms/builtins/OpHelpers.cpp index 0a30232993..de6100f3b3 100644 --- a/src/OpenColorIO/transforms/builtins/OpHelpers.cpp +++ b/src/OpenColorIO/transforms/builtins/OpHelpers.cpp @@ -66,9 +66,10 @@ void CreateLut(OpRcPtrVec & ops, for (unsigned long idx = 0; idx < lutDimension; ++idx) { - values[idx * 3 + 0] = lutValueGenerator(double(idx) / (lutDimension - 1.)); - values[idx * 3 + 1] = lutValueGenerator(double(idx) / (lutDimension - 1.)); - values[idx * 3 + 2] = lutValueGenerator(double(idx) / (lutDimension - 1.)); + const float value = lutValueGenerator(double(idx) / (lutDimension - 1.)); + values[idx * 3 + 0] = value; + values[idx * 3 + 1] = value; + values[idx * 3 + 2] = value; } CreateLut1DOp(ops, lut, TRANSFORM_DIR_FORWARD); @@ -132,9 +133,10 @@ void CreateHalfLut(OpRcPtrVec & ops, std::function lutValueGenera value = halfValue.isNegative() ? -HALF_MAX : HALF_MAX; } - values[idx * 3 + 0] = lutValueGenerator(value); - values[idx * 3 + 1] = lutValueGenerator(value); - values[idx * 3 + 2] = lutValueGenerator(value); + const float outValue = lutValueGenerator(value); + values[idx * 3 + 0] = outValue; + values[idx * 3 + 1] = outValue; + values[idx * 3 + 2] = outValue; } CreateLut1DOp(ops, lut, TRANSFORM_DIR_FORWARD);