You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
bug: ImageInput::open() forces full OpenColorIO config initialization even when no color management is requested #5490
Opening a single image adds a fixed ~20 ms to the first ImageInput::open()
in a process, spent constructing the default OpenColorIO config. This happens
for callers that only want metadata and never perform a color transform.
ColorConfig::default_colorconfig() is a function-local static ColorConfig,
so the first call constructs the whole config. Several readers call set_colorspace() unconditionally in open(), among them:
OIIO 3.1.14.0 (vcpkg), release build, JPEG input (960x639, 3 ch), median of
5 runs. Timed region is ImageInput::open() plus reading the ImageSpec.
The only difference between the two rows is one added line; OIIO is not
rebuilt.
median
range
as-is
0.0208 s
0.0203 – 0.0217
ColorConfig::default_colorconfig(); called before the timer
0.00049 s
0.00045 – 0.00055
Spread is under 10% in both, so this is not a cold-cache artifact. Standalone
reproducer attached.
The cost scales with the OpenColorIO version: ~10 ms with OCIO 2.2.1, ~20 ms with OCIO 2.5.2, both with no OCIO environment variable set.
Why it looks avoidable
ColorConfig::set_colorspace() needs the config for exactly one thing:
if (!equivalent(colorspace, "sRGB"))
spec.erase_attribute("Exif:ColorSpace");
In JpgInput::open(), set_colorspace() runs at ~line 329 while decode_exif() runs at ~line 352, so at that point Exif:ColorSpace, tiff:ColorSpace, tiff:PhotometricInterpretation and oiio:Gamma are all
absent from the freshly constructed spec. Every erase is a no-op and the equivalent() result cannot change the outcome.
The tree already does this the cheap way elsewhere. src/png.imageio/png_pvt.h
makes the same kind of assumption without touching the config:
Have ImageSpec::set_colorspace() avoid touching default_colorconfig()
when none of the attributes it would erase are present.
Make the default ColorConfig construction cheaper or lazier.
Happy to prepare a PR for either if you have a preference.
Environment
OpenImageIO 3.1.14.0 (vcpkg), OpenColorIO 2.5.2, no OCIO environment
variable set (so this is the built-in config). Linux 6.18 (WSL2), gcc 13.3.0,
Intel i7-5820K. The absolute cost will be lower on newer hardware; the claim
here is the fixed cost that disappears when the config is constructed before
the timed region, not the specific number.
I replied in many more words in #4629, but basically, what I'm proposing amounts to readers not invoking set_colorspace() at all, and setting the 'oiio:ColorSpace' attribute directly (to known colorInteropID strings); and otherwise ensuring that ColorConfig instances properly recognize those values as valid color spaces.
In other words, readers won't be creating new ColorConfig instances, they'll just be setting attributes in the spec; and those attributes will be reconciled with the active color config as lazily as possible.
So the fundamental problem is that there's more overhead than we'd like in OCIO when you set up a config, including the default built-in configs?
And ImageSpec::set_colorspace is a really thin wrapper for default_colorconfig().set_colorspace(spec, colorspace), which mostly does some inexpensive operations on the spec, except for one call to ColorConig::equivalent(). But the problem is that merely calling this method means that the ColorConfig has to been constructed.
So how about this:
Move most of the spec-related logic from ColorConfig::set_colorspace into ImageSpec::set_colorspace, so now you have
void
ImageSpec::set_colorspace(string_view colorspace)
{
// HERE, do everything that ColorConfig::set_colorspace used to do, EXCEPT the part
// where it says
// if (!equivalent(colorspace, "srgb_rec709_scene"))
// spec.erase_attribute("Exif:ColorSpace");
// do those things
// Now, the magic bits:
if (colorsace != "srgb_rec709_scene" && spec.has_attribute("Exif:ColorSpace"))
if (!default_colorconfig().equivalent(colorspace, "srgb_rec709_scene"))
spec.erase_attribute("Exif:ColorSpace");
}
See? Now it's only in the specific circumstance that you might need to erase that attribute that it even does the check that triggers construction of the default_colorconfig.
Just need to double check that we aren't directly calling ColorConfig::set_colorspace anywhere else that will need to get directed to ImageSpec::set_colorspace.
Just need to double check that we aren't directly calling ColorConfig::set_colorspace anywhere else that will need to get directed to ImageSpec::set_colorspace.
This makes me nervous. I'm doing lots of stuff to set_colorspace. Need to double check, but... is there any reason why we can't just have the readers set oiio:ColorSpace directly instead of invoking set_colorspace at this stage?
This makes me nervous. I'm doing lots of stuff to set_colorspace. Need to double check, but... is there any reason why we can't just have the readers set oiio:ColorSpace directly instead of invoking set_colorspace at this stage?
In general, set_colorspace was supposed to be preferred over just a raw set of "oiio:ColorSpace" because it was a place where we could do other things, like clearing attributes that were contradicted by the choice of colorspace.
But I suppose that for an input plugin, it's constructing the whole spec itself, so it's not necessarily a case of "you don't know what else is there."
So, sure, I guess it's fine to have particular readers just set the attribute and no call set_colorspace, if you are sure it's safe.
I continue to think that ImageSpec::set_colorspace should not need to cause a ColorConfig to be instantiated (even the default one) except in cases where it's needed.
But I suppose that for an input plugin, it's constructing the whole spec itself, so it's not necessarily a case of "you don't know what else is there."
Yes -- I think, beyond bringing encodings to RGB(A) full range float buffers, readers should probably take a passive role, and just persist metadata as-is, to whatever degree we can, and leave the reconciliation of oiio:ColorSpace from the various known "facts" collected by the reader to a downstream ColorConfig-aware process.
To be perfectly honest, I'm planning on proposing that readers not directly populate oiio:ColorSpaceat all, and, instead, populate the colorInteropID attribute; which would leave room for the actual reconciliation of oiio:ColorSpace to include the OCIO Config's FileRules as part of the deferred resolution process (instead of having readers always presuming that file metadata and/or format defaults always takes precedence over file naming). Just something to think about.
In general, set_colorspace was supposed to be preferred over just a raw set of "oiio:ColorSpace" because it was a place where we could do other things, like clearing attributes that were contradicted by the choice of colorspac
Yes, absolutely... it's just not clear to me how we would empirically assess the validity of potentially contradictory color metadata attributes in the spec without an actual OCIO color space to introspect and compare against (without resorting to hand-rolled heuristics that only cover a handful of real-world cases).
I continue to think that ImageSpec::set_colorspace should not need to cause a ColorConfig to be instantiated (even the default one) except in cases where it's needed.
I'm not totally against this, but I'm struggling to understand what you have in mind. To me, the clearing of contradictory metadata aspect of set_colorspace is pretty contingent on having a valid basis for comparison (or, at minimum, a valid alternative!). Specifically, I don't think it's safe to automatically clear attributes just because we're using set_colorspace to set oiio:ColorSpace -- if that value cannot be interpreted by a ColorConfig later, then we've lost information that might have otherwise been used to reconcile an appropriate OCIO Processor for an IBA that needs a ColorConfig...
Yes - that sounds right. Deferring the config until something actually needs it removes the cost at the source, instead of special-casing readers one at a time.
Two notes.
Since the measurements in both threads have been EXR so far, it may be worth connecting this back to lgritz's "(b) do we care" in #4629: the cost isn't EXR-specific. As in the description above, jpeginput.cpp calls set_colorspace("srgb_rec709_scene") unconditionally in open(), so any process that opens a single JPEG pays for a config it never uses. hdrinput.cpp and ddsinput.cpp do the same. For a short-lived process - iinfo, a thumbnailer, an asset scanner - that is most of the cost of reading a header.
On the narrower change proposed here: I think it already covers both of those. For JPEG the value being set issrgb_rec709_scene, so the first condition short-circuits. For HDR there is no Exif:ColorSpace on the spec at all - and in JpgInput::open() there wouldn't be one at that point either, since decode_exif() runs after the set_colorspace() call.
@zachlewis - do you want that intermediate change kept separate from your PR? If it's useful standalone I'm happy to put it up. Either way, I can run my pinned 2.5.16.0 / 3.0.0.3 / 3.1.14.0 benchmark against your branch once it's open.
readers should [...] just persist metadata as-is, to whatever degree we can, and leave the reconciliation of oiio:ColorSpace from the various known "facts" collected by the reader to a downstream ColorConfig-aware process.
Agreed, that makes sense.
To be perfectly honest, I'm planning on proposing that readers not directly populate oiio:ColorSpaceat all, and, instead, populate the colorInteropID attribute; which would leave room for the actual reconciliation of oiio:ColorSpace to include the OCIO Config's FileRules as part of the deferred resolution process (instead of having readers always presuming that file metadata and/or format defaults always takes precedence over file naming). Just something to think about.
Makes sense, I see.
Yes, absolutely... it's just not clear to me how we would empirically assess the validity of potentially contradictory color metadata attributes in the spec without an actual OCIO color space to introspect and compare against (without resorting to hand-rolled heuristics that only cover a handful of real-world cases).
I'm not totally against this, but I'm struggling to understand what you have in mind.
Oh, I'm talking about obvious things like
// BAD -- always constructs a ColorConfig
if (!equivalent(myspace, "rec_709_scene"))
spec.erase_attribute("thing that contradicts");
// GOOD -- only constructs ColorConfig if truly needed
if (myspace != "rec_709_scene"
&& spec.has_attribute("thing that contradicts")
&& !equivalent(myspace, "rec_709_scene"))
spec.erase_attribute("thing that contradicts");
There's no need to erase the attribute if it doesn't exist, and if myspace is exactly equal to "rec_709_scene", there is no need to call equivalent(), so the structure of the if && && prevents the expensive call in most cases.
Maybe that's what you meant by "hand-rolled heuristics", but IMHO, as long as OCIO ColorConfig has a noticeable speed penalty to construct, even of a built-in config (which one might naively imagine to be free because it's the same on every run?), it's worth a little bit of refactoring to do it lazily if there are common cases where the cost is not necessary.
Ah, I see your point...! yeah, you know what, that makes sense to me. In fact, I'm already sort of doing some of that, hardcoding chromaticities for the CIF color spaces, and I believe we've got something similar going on with CICP... maybe the thing to do is have set_colorspace "short-circuit" any comparisons with other metadata entirely for the set of published CIF color spaces, and just immediately set the corresponding chromaticities and "oiio:Gamma" attributes correctly in place, per a hardcoded table, no config needed. This sounds pretty reasonable to me!
@bartosz216 -- I may be mistaken -- and correct me if I am -- but I think it's not quite safe yet to directly set oiio:ColorSpace to arbitrary colorInteropID values, at least without causing some regressions in some cases. Or, I should say, I think it's safe to directly set oiio:ColorSpace only if the value we're setting is "srgb_rec709_scene", "srgb_rec709_display", "lin_rec709_scene", "lin_ap1_scene", or "scene_linear" (and, currently, a handful of aliases for the aforementioned that we're trying to deprecate). These strings "get a pass", because, currently, the ColorConfig initialization phase attempts to identify definitional matches for those color spaces in the given config ahead of time. So, in areas you've identified where, e.g., the png reader is setting oiio:ColorSpace directly to "srgb_rec709_scene", it only gets away with doing so because [color-aware] IBAs always ColorConfig::resolve color space values; and that particular function encounters that particular string, it returns the name of the sRGB color space that was found during the ColorConfig instantiation. So setting "srgb_rec709_scene" is kind of invoking a promise that the name of the actual corresponding color space in the ColorConfig used by the IBA will be swapped in at the right moment, if it possibly can be; whereas, currently, I believe (and may be mistaken), ColorConfig::set_colorspace attempts to see if a known alias from OCIO-2.3 and OCIO-2.4's builtin configs happens to exist in the config for the published set of colorInteropIDs. It's not a super robust solution, but it's what we currently have in place, and it works well enough for cases where users are not providing custom OCIO configs.
ANYWAY, long story short, my plan involves totally revamping the ColorConfig initialization / matching heuristics bit, which would make it safe to assign config-agnostic colorInteropIDs directly to oiio:ColorSpace (or, preferably, to the colorInteropID attribute instead), and would automatically defer the actual resolution until after a ColorConfig has been initialized (outside of the reader)... stay tuned!
You're right, thanks for spelling that out. I was reading pnginput.cpp setting oiio:ColorSpace directly as evidence that the cheap path is generally available,
and it isn't - it works there because srgb_rec709_scene is one of the names
ColorConfig resolves definitionally. Useful to know the guarantee is that narrow.
For what it's worth, the three readers I flagged all land inside that safe set: jpeginput.cpp sets srgb_rec709_scene, hdrinput.cpp and ddsinput.cpp set lin_rec709_scene - which lines up with #5507 short-circuiting on the literal srgb_rec709_scene.
Since all the measurements so far are on Apple silicon, I'll build #5507 against
my pinned vcpkg tree and post before/after numbers for JPEG and EXR on Linux
x86-64, gcc 13.3, OCIO 2.5.2. Anything in particular worth covering while I'm
there?
________________________________
From: Tatar ***@***.***>
Sent: Wednesday, 30 September 2026 16:32:00
To: AcademySoftwareFoundation/OpenImageIO ***@***.***>
Cc: Zach Lewis ***@***.***>; Mention ***@***.***>
Subject: Re: [AcademySoftwareFoundation/OpenImageIO] bug: ImageInput::open() forces full OpenColorIO config initialization even when no color management is requested (Issue #5490)
[https://avatars.githubusercontent.com/u/84987627?s=20&v=4]bartosz216 left a comment (AcademySoftwareFoundation/OpenImageIO#5490)<#5490 (comment)>
You're right, thanks for spelling that out. I was reading pnginput.cpp setting
oiio:ColorSpace directly as evidence that the cheap path is generally available,
and it isn't - it works there because srgb_rec709_scene is one of the names
ColorConfig resolves definitionally. Useful to know the guarantee is that narrow.
For what it's worth, the three readers I flagged all land inside that safe set:
jpeginput.cpp sets srgb_rec709_scene, hdrinput.cpp and ddsinput.cpp set
lin_rec709_scene - which lines up with #5507<#5507> short-circuiting on the literal
srgb_rec709_scene.
Since all the measurements so far are on Apple silicon, I'll build #5507<#5507> against
my pinned vcpkg tree and post before/after numbers for JPEG and EXR on Linux
x86-64, gcc 13.3, OCIO 2.5.2. Anything in particular worth covering while I'm
there?
—
Reply to this email directly, view it on GitHub<#5490?email_source=notifications&email_token=AARAC4CWTMJCEHCJYWGNMLD5RVUUBA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTKOJRHEZDEMBVGEZ2M4TFMFZW63VHNVSW45DJN5XKKZLWMVXHJLDGN5XXIZLSL5RWY2LDNM#issuecomment-5919220513>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AARAC4ETSZFLPPQC2AQJ67D5RVUUBAVCNFSNUABDKJSXA33TNF2G64TZHMYTGMRSGI4DIO2JONZXKZJ3GU2TINRSG43TSNRXUF3AE>.
You are receiving this because you were mentioned.Message ID: ***@***.***>
Following up on the numbers I promised, now post-merge: Linux x86-64 (WSL2),
gcc 13.3, OCIO 2.5.2, release builds of OIIO from the same vcpkg tree.
First ImageInput::open() + spec() in a fresh process; 10 interleaved
before/after runs, first pair discarded, median (range), ms:
before (merge-base 5d186c29e)
after (main f05656438)
JPEG
21.267 (20.976 - 21.710)
0.671 (0.625 - 0.702)
EXR, untagged (control)
0.837 (0.790 - 0.961)
0.839 (0.781 - 0.929)
With OPENIMAGEIO_LOG_TIMES=2, ColorConfig::init no longer appears at all for
a plain JPEG open. It still does for oiiotool --colorconvert, where it averages
21.46 ms per init - close to the ~20.6 ms that disappeared from the JPEG open.
Incidentally, the oiiotool run logs ColorConfig::init twice (43 ms total) -
two config loads in one process, if I'm reading the counter right - which may be
relevant to the shared-config change mentioned in #4629.
Hey, thanks again, Tatar.
I think colorconvert is almost always going to load at least one OCIO
config, because that particular IBA is a wrapper around an OCIO function,
which necessarily requires a config. Arguably, we could probably do more to
determine if the IBA is gonna be a no-op, based on the parameters. But I
think it’s reasonable for users specifying the —colorconvert command to
expect to pay the cost of initializing a ColorConfig.
Now, re: an OCIO config being loaded more than once — IIRC, what I
suspect is happening is, the default OCIO config is loaded at least once
during every ColorConfig init (during the classification stage, as part of
the effort to identify certain color spaces in the given OCIO config).
In any case, the shared config cache stuff should help quite a bit here — I
may be mistaken, but it might cut the cost of loading a default ColorConfig
in half. No promises.
On Tue, Oct 6, 2026 at 7:00 PM Tatar ***@***.***> wrote:
*bartosz216* left a comment (AcademySoftwareFoundation/OpenImageIO#5490)
<#5490 (comment)>
Following up on the numbers I promised, now post-merge: Linux x86-64
(WSL2),
gcc 13.3, OCIO 2.5.2, release builds of OIIO from the same vcpkg tree.
First ImageInput::open() + spec() in a fresh process; 10 interleaved
before/after runs, first pair discarded, median (range), ms:
before (merge-base 5d186c2) after (main f056564)
JPEG 21.267 (20.976 - 21.710) 0.671 (0.625 - 0.702)
EXR, untagged (control) 0.837 (0.790 - 0.961) 0.839 (0.781 - 0.929)
With OPENIMAGEIO_LOG_TIMES=2, ColorConfig::init no longer appears at all
for
a plain JPEG open. It still does for oiiotool --colorconvert, where it
averages
21.46 ms per init - close to the ~20.6 ms that disappeared from the JPEG
open.
Incidentally, the oiiotool run logs ColorConfig::init twice (43 ms total)
-
two config loads in one process, if I'm reading the counter right - which
may be
relevant to the shared-config change mentioned in #4629
<#4629>.
Thanks both - this was a pleasure to follow.
—
Reply to this email directly, view it on GitHub
<#5490?email_source=notifications&email_token=AARAC4DXO7XHDOSRAFU3IZD5SV2PPA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTMMBSGY4TSNRSHEZKM4TFMFZW63VHNVSW45DJN5XKKZLWMVXHJLDGN5XXIZLSL5RWY2LDNM#issuecomment-6026996292>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AARAC4HFMRH74IWV62B7ZVT5SV2PPAVCNFSNUABDKJSXA33TNF2G64TZHMYTGMRSGI4DIO2JONZXKZJ3GU2TINRSG43TSNRXUF3AE>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
Activity
zachlewis commentedon Sep 23, 2026
I replied in many more words in #4629, but basically, what I'm proposing amounts to readers not invoking set_colorspace() at all, and setting the 'oiio:ColorSpace' attribute directly (to known colorInteropID strings); and otherwise ensuring that ColorConfig instances properly recognize those values as valid color spaces.
In other words, readers won't be creating new ColorConfig instances, they'll just be setting attributes in the spec; and those attributes will be reconciled with the active color config as lazily as possible.
Sound good?
lgritz commentedon Sep 23, 2026
So the fundamental problem is that there's more overhead than we'd like in OCIO when you set up a config, including the default built-in configs?
And ImageSpec::set_colorspace is a really thin wrapper for
default_colorconfig().set_colorspace(spec, colorspace), which mostly does some inexpensive operations on the spec, except for one call to ColorConig::equivalent(). But the problem is that merely calling this method means that the ColorConfig has to been constructed.So how about this:
Move most of the spec-related logic from ColorConfig::set_colorspace into ImageSpec::set_colorspace, so now you have
See? Now it's only in the specific circumstance that you might need to erase that attribute that it even does the check that triggers construction of the default_colorconfig.
Just need to double check that we aren't directly calling ColorConfig::set_colorspace anywhere else that will need to get directed to ImageSpec::set_colorspace.
zachlewis commentedon Sep 24, 2026
This makes me nervous. I'm doing lots of stuff to set_colorspace. Need to double check, but... is there any reason why we can't just have the readers set
oiio:ColorSpacedirectly instead of invoking set_colorspace at this stage?zachlewis commentedon Sep 24, 2026
(Or... I mean, it's fine as an intermediate fix; and I can work around it, if that's the direction we want to go.)
lgritz commentedon Sep 24, 2026
In general, set_colorspace was supposed to be preferred over just a raw set of "oiio:ColorSpace" because it was a place where we could do other things, like clearing attributes that were contradicted by the choice of colorspace.
But I suppose that for an input plugin, it's constructing the whole spec itself, so it's not necessarily a case of "you don't know what else is there."
So, sure, I guess it's fine to have particular readers just set the attribute and no call set_colorspace, if you are sure it's safe.
I continue to think that ImageSpec::set_colorspace should not need to cause a ColorConfig to be instantiated (even the default one) except in cases where it's needed.
zachlewis commentedon Sep 24, 2026
Yes -- I think, beyond bringing encodings to RGB(A) full range float buffers, readers should probably take a passive role, and just persist metadata as-is, to whatever degree we can, and leave the reconciliation of
oiio:ColorSpacefrom the various known "facts" collected by the reader to a downstream ColorConfig-aware process.To be perfectly honest, I'm planning on proposing that readers not directly populate
oiio:ColorSpaceat all, and, instead, populate thecolorInteropIDattribute; which would leave room for the actual reconciliation ofoiio:ColorSpaceto include the OCIO Config's FileRules as part of the deferred resolution process (instead of having readers always presuming that file metadata and/or format defaults always takes precedence over file naming). Just something to think about.Yes, absolutely... it's just not clear to me how we would empirically assess the validity of potentially contradictory color metadata attributes in the spec without an actual OCIO color space to introspect and compare against (without resorting to hand-rolled heuristics that only cover a handful of real-world cases).
I'm not totally against this, but I'm struggling to understand what you have in mind. To me, the clearing of contradictory metadata aspect of
set_colorspaceis pretty contingent on having a valid basis for comparison (or, at minimum, a valid alternative!). Specifically, I don't think it's safe to automatically clear attributes just because we're usingset_colorspaceto setoiio:ColorSpace-- if that value cannot be interpreted by a ColorConfig later, then we've lost information that might have otherwise been used to reconcile an appropriate OCIO Processor for an IBA that needs a ColorConfig...zachlewis commentedon Sep 24, 2026
(Oh, and to be perfectly clear, I am still making it safe to set
oiio:ColorSpacedirectly to a known colorInteropID, should someone want to)bartosz216 commentedon Sep 24, 2026
Yes - that sounds right. Deferring the config until something actually needs it removes the cost at the source, instead of special-casing readers one at a time.
Two notes.
Since the measurements in both threads have been EXR so far, it may be worth connecting this back to lgritz's "(b) do we care" in #4629: the cost isn't EXR-specific. As in the description above,
jpeginput.cppcallsset_colorspace("srgb_rec709_scene")unconditionally inopen(), so any process that opens a single JPEG pays for a config it never uses.hdrinput.cppandddsinput.cppdo the same. For a short-lived process -iinfo, a thumbnailer, an asset scanner - that is most of the cost of reading a header.On the narrower change proposed here: I think it already covers both of those. For JPEG the value being set is
srgb_rec709_scene, so the first condition short-circuits. For HDR there is noExif:ColorSpaceon the spec at all - and inJpgInput::open()there wouldn't be one at that point either, sincedecode_exif()runs after theset_colorspace()call.@zachlewis - do you want that intermediate change kept separate from your PR? If it's useful standalone I'm happy to put it up. Either way, I can run my pinned 2.5.16.0 / 3.0.0.3 / 3.1.14.0 benchmark against your branch once it's open.
lgritz commentedon Sep 24, 2026
Agreed, that makes sense.
Makes sense, I see.
Oh, I'm talking about obvious things like
There's no need to erase the attribute if it doesn't exist, and if myspace is exactly equal to "rec_709_scene", there is no need to call
equivalent(), so the structure of theif && &&prevents the expensive call in most cases.Maybe that's what you meant by "hand-rolled heuristics", but IMHO, as long as OCIO ColorConfig has a noticeable speed penalty to construct, even of a built-in config (which one might naively imagine to be free because it's the same on every run?), it's worth a little bit of refactoring to do it lazily if there are common cases where the cost is not necessary.
zachlewis commentedon Sep 25, 2026
Ah, I see your point...! yeah, you know what, that makes sense to me. In fact, I'm already sort of doing some of that, hardcoding chromaticities for the CIF color spaces, and I believe we've got something similar going on with CICP... maybe the thing to do is have set_colorspace "short-circuit" any comparisons with other metadata entirely for the set of published CIF color spaces, and just immediately set the corresponding chromaticities and "oiio:Gamma" attributes correctly in place, per a hardcoded table, no config needed. This sounds pretty reasonable to me!
@bartosz216 -- I may be mistaken -- and correct me if I am -- but I think it's not quite safe yet to directly set oiio:ColorSpace to arbitrary colorInteropID values, at least without causing some regressions in some cases. Or, I should say, I think it's safe to directly set oiio:ColorSpace only if the value we're setting is "srgb_rec709_scene", "srgb_rec709_display", "lin_rec709_scene", "lin_ap1_scene", or "scene_linear" (and, currently, a handful of aliases for the aforementioned that we're trying to deprecate). These strings "get a pass", because, currently, the ColorConfig initialization phase attempts to identify definitional matches for those color spaces in the given config ahead of time. So, in areas you've identified where, e.g., the png reader is setting
oiio:ColorSpacedirectly to "srgb_rec709_scene", it only gets away with doing so because [color-aware] IBAs always ColorConfig::resolve color space values; and that particular function encounters that particular string, it returns the name of the sRGB color space that was found during the ColorConfig instantiation. So setting "srgb_rec709_scene" is kind of invoking a promise that the name of the actual corresponding color space in the ColorConfig used by the IBA will be swapped in at the right moment, if it possibly can be; whereas, currently, I believe (and may be mistaken), ColorConfig::set_colorspace attempts to see if a known alias from OCIO-2.3 and OCIO-2.4's builtin configs happens to exist in the config for the published set of colorInteropIDs. It's not a super robust solution, but it's what we currently have in place, and it works well enough for cases where users are not providing custom OCIO configs.ANYWAY, long story short, my plan involves totally revamping the ColorConfig initialization / matching heuristics bit, which would make it safe to assign config-agnostic colorInteropIDs directly to oiio:ColorSpace (or, preferably, to the
colorInteropIDattribute instead), and would automatically defer the actual resolution until after a ColorConfig has been initialized (outside of the reader)... stay tuned!fix(imageio): don't consult the color config when reading images
fix(imageio): don't consult the color config when reading images
fix(imageio): don't consult the color config when reading images
bartosz216 commentedon Sep 30, 2026
You're right, thanks for spelling that out. I was reading
pnginput.cppsettingoiio:ColorSpacedirectly as evidence that the cheap path is generally available,and it isn't - it works there because
srgb_rec709_sceneis one of the namesColorConfig resolves definitionally. Useful to know the guarantee is that narrow.
For what it's worth, the three readers I flagged all land inside that safe set:
jpeginput.cppsetssrgb_rec709_scene,hdrinput.cppandddsinput.cppsetlin_rec709_scene- which lines up with #5507 short-circuiting on the literalsrgb_rec709_scene.Since all the measurements so far are on Apple silicon, I'll build #5507 against
my pinned vcpkg tree and post before/after numbers for JPEG and EXR on Linux
x86-64, gcc 13.3, OCIO 2.5.2. Anything in particular worth covering while I'm
there?
zachlewis commentedon Sep 30, 2026
brechtvl commentedon Oct 1, 2026
For context, there is much room for optimization in OpenColorIO config loading as well: AcademySoftwareFoundation/OpenColorIO/pull/2357.
fix(imageio): don't consult the color config when reading images
fix(color): load the color config on first use, not on construction
fix(color): load the color config on first use, not on construction
bartosz216 commentedon Oct 6, 2026
Following up on the numbers I promised, now post-merge: Linux x86-64 (WSL2),
gcc 13.3, OCIO 2.5.2, release builds of OIIO from the same vcpkg tree.
First
ImageInput::open()+spec()in a fresh process; 10 interleavedbefore/after runs, first pair discarded, median (range), ms:
5d186c29e)f05656438)With
OPENIMAGEIO_LOG_TIMES=2,ColorConfig::initno longer appears at all fora plain JPEG open. It still does for
oiiotool --colorconvert, where it averages21.46 ms per init - close to the ~20.6 ms that disappeared from the JPEG open.
Incidentally, the
oiiotoolrun logsColorConfig::inittwice (43 ms total) -two config loads in one process, if I'm reading the counter right - which may be
relevant to the shared-config change mentioned in #4629.
Thanks both - this was a pleasure to follow.
zachlewis commentedon Oct 6, 2026
fix(color): load the color config on first use, not on construction (A…
fix(color): load the color config on first use, not on construction (A…
fix(color): load the color config on first use, not on construction (A…
fix(color): load the color config on first use, not on construction (A…