Skip to content

lightdm: move out of loop strlen call - #446

Merged
jpeisach merged 1 commit into
ubuntu:mainfrom
GermanAizek:strlen-out-of-loop
Aug 4, 2026
Merged

jpeisach merged 1 commit into
ubuntu:mainfrom
GermanAizek:strlen-out-of-loop

Conversation

@GermanAizek

Copy link
Copy Markdown
Contributor

@jpeisach

Fix common C/C++ compiler flaw is that it doesn't optimize strlen calls inside loops.

Reference:

Since I started contributing to heavily optimized AV1 decoder (ffmpeg dav1d), there are high performance requirements. I experimentally found out that putting calculated expressions from the body of the loop into separate constants gives a strong two-fold increase. What is strange is the C/C++ compiler that GCC and Clang on -O3 cannot automatically optimize.

It's also visually more readable with a separate const variable.

@jpeisach jpeisach added this to the 1.33.0 milestone Aug 2, 2026
@jpeisach

jpeisach commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator

I don't see any harm doing this - we don't want to compute strlen multiple times anyway

@jpeisach
jpeisach merged commit 0c32cb9 into ubuntu:main Aug 4, 2026
2 checks passed
@tintou

tintou commented Aug 7, 2026 •

Copy link
Copy Markdown
Contributor

Here we were doing strlen of constant expression, there shouldn't be any difference, the example you're linking is not the same as this, the only real occurrence is at src/session.c

@jpeisach

jpeisach commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator

it's still a constant calculated expression. Also I imagine on builds with no compiler optimization at all, this would prevent the call from being made each time there is a .desktop file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants