OpenColorIO icon indicating copy to clipboard operation
OpenColorIO copied to clipboard

Text format (e.g. IridasCube) parsing optimizations

Open aras-p opened this issue 1 year ago • 3 comments

Primarily driven by a wish to increase performance of parsing .cube files. But the functions that are added or changed are used across parsing of all/most of text based formats.

With these changes, parsing "Khronos PBR Neutral" Iridas .cube file (5.4MB) on Ryzen 5950X / VS2022 Release build: 167ms -> 126ms. Parsing the same file in CLF format: 150ms -> 137ms.

What the PR does is:

  • Add locale independent IsSpace(char). Somewhat similar to 3aab90d31, whitespace trimming perhaps should not be locale dependent.
  • Add IsEmptyOrWhiteSpace() and use that inside ParseUtils::nextline, instead of doing Trim(line).empty().
  • Add StringUtils::StartsWith(char) and use that in various parsers that were constructing whole std::string object just to check for a single character.
  • When building for C++17 or later, NumberUtils can use standard <charconv> from_chars functions (except on Apple platforms, where those are not implemented for floating point types as of Xcode 15). This has advantage of not having to deal with errno or locales. Saves some thread local storage accesses and function calls (e.g. on Windows errno is actually a function call).
    • Turns out that NumberUtils::from_chars was only indirectly covered by tests, and as XML parser utils tests point out, it should be able to handle hex floats and so on. So all that is implemented there, and explicitly covered by tests/utils/NumberUtils_tests.cpp.
    • There's a CMake setup change that adds /Zc:__cplusplus flag for MSVC; for backwards compat reasons it does not report proper C++ version detection defines otherwise.

aras-p avatar Oct 01 '24 10:10 aras-p

Apologies for the delay in CI @aras-p, we have to manually approve the workflows due to our current GitHub settings. Trying to see if we can update that or merge your other PR which should also work.

remia avatar Oct 02 '24 10:10 remia

@remia thanks! I admit I did not expect that this PR would need so many failed iterations. <charconv> is a tough beast, it seems :)

aras-p avatar Oct 02 '24 10:10 aras-p

Doing some test on an Intel MBP, Xcode 16, it seems to still not support from_chars()

Yeah, Apple's Clang/STL keeps on being "special". Some other software (e.g. Blender) works around this whole issue by embedding https://github.com/fastfloat/fast_float and using that instead of <charconv>

aras-p avatar Oct 17 '24 04:10 aras-p

Now that two reviews have been done, is there something expected from my side to move forward with this PR?

aras-p avatar Dec 06 '24 12:12 aras-p

@aras-p , apologies for the delay in getting this merged. Our CI system is currently having some problems which is causing checks to fail, but I don't think we will need you to do anything more on this one.

It's great to have your participation on OCIO -- we'll try to get your next PR merged more quickly! ;)

doug-walker avatar Dec 06 '24 17:12 doug-walker