Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ExifKey::Impl::tagName() is Slow #3153

Open
eyesoftime opened this issue Feb 7, 2025 · 3 comments · May be fixed by #3157
Open

ExifKey::Impl::tagName() is Slow #3153

eyesoftime opened this issue Feb 7, 2025 · 3 comments · May be fixed by #3157
Labels

Comments

@eyesoftime
Copy link

Describe the bug

As the title says: std::string ExifKey::Impl::tagName() const is slow.

To Reproduce

I've been trying to track down why readMetadata is slow for my Sony a99ii ARW files. Slow as in order of magnitude to two slower than with JPEGs or TIFFs. Found one of the issues to be here:

exiv2/src/tags.cpp

Lines 182 to 184 in b917b34

std::ostringstream os;
os << "0x" << std::setw(4) << std::setfill('0') << std::right << std::hex << tag_;
return os.str();

It gets executed about two thousand times accumulating over 100ms. Converting a short unsigned int to a four-digit hex string shouldn't be that big of an issue. Testing around I found that the following cuts the time about three orders of magnitude. Feel free to substitute those three lines with something like the following. There's likely an even more efficient way but at this point it hardly matters for now. I'm down with metadata loading from 180ms to about 19ms but I'll have to dig around some more to see if there are other fairly obvious issues.

Expected behavior

I propose something like this instead of the three lines linked above. I'll defer to your judgement on the Endianness issues if any.

constexpr static char m[] { "0123456789abcdef" };
char s[] { "0x0000" };
s[2] = m[(tag_ >> 12) & 0xf];
s[3] = m[(tag_ >> 8) & 0xf];
s[4] = m[(tag_ >> 4) & 0xf];
s[5] = m[tag_ & 0xf];
return s;

Desktop (please complete the following information):

  • OS and version: Win10
  • Exiv2 version and source: 0.28.3
  • Compiler and version: Clang 19.1.7
  • Compilation mode and/or compiler flags: debugoptimized meson build, using as a static library
@eyesoftime eyesoftime added the bug label Feb 7, 2025
@neheb
Copy link
Collaborator

neheb commented Feb 9, 2025

How about

return stringFormat("0x{:04x}", tag_);

?

@neheb neheb linked a pull request Feb 9, 2025 that will close this issue
@kmilos
Copy link
Collaborator

kmilos commented Feb 9, 2025

How about

Should be good for main branch. We don't have neither libfmt nor std::format on 0.28.x, so we probably won't change anything there unfortunately....

@eyesoftime
Copy link
Author

return stringFormat("0x{:04x}", tag_);

Sure, why not. Quick test shows it to be about 5x slower than what I wrote above but it does cut down two orders of magnitude so it should be much better already.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants