Skip to content

Bunch of assorted perf improvements of hot path functions#8447

Merged
alexey-tikhonov merged 3 commits intoSSSD:masterfrom
alexey-tikhonov:hotpath-helpers-optimization
Feb 17, 2026
Merged

Bunch of assorted perf improvements of hot path functions#8447
alexey-tikhonov merged 3 commits intoSSSD:masterfrom
alexey-tikhonov:hotpath-helpers-optimization

Conversation

@alexey-tikhonov
Copy link
Member

@alexey-tikhonov alexey-tikhonov commented Feb 12, 2026

Those patches are based on a profiling of a following test case:

  • users tu1 and tu2 are members of 5k LDAP groups (RFC2307 case, no nested groups)
  • SSSD stared with an empty cache
  • time id tu1@ldap.test | tr ',' '\n' | wc -l is executed

(Note you need to tweak both LDAP (limits) and SSSD (timeout, client_idle_timeout) settings to make this req complete successfully).

Combined, those patches reduce lookup time on my laptom from ~51+s to ~45-s (at least with debug_microseconds = true)

Note that much more fruitful optimizations are possible under sdap_initgr_common_store(), including getting rid of O(N^2) loop over sdap_get_group_primary_name() in sdap_add_incomplete_groups(), and some of those optimization will make patches in this PR kind of obsolete for this specific test case. But given that those helpers are heavily used across all code base, I think it's still worth consideration.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces several performance improvements for hot-path functions. The changes include using conditional debug logging to avoid unnecessary work, and adding caching to avoid repeated string conversions.

My review has identified two main issues:

  1. A potential portability bug in sss_is_ascii_lowercase due to comparing a char against 0x7F without casting to unsigned char.
  2. A critical thread-safety issue in the new caching function sss_get_lc_dom_name, which uses static variables without any locking, leading to race conditions in a multi-threaded environment.

Please address these points to ensure the code is both correct and robust.

Copy link
Contributor

@justin-stephenson justin-stephenson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack, changes make sense to me. Thank you.

@alexey-tikhonov alexey-tikhonov force-pushed the hotpath-helpers-optimization branch from 2a0c7c9 to b8944ca Compare February 12, 2026 15:32
@alexey-tikhonov
Copy link
Member Author

(amended commit message of one of patches)

@alexey-tikhonov alexey-tikhonov added the coverity Trigger a coverity scan label Feb 14, 2026
@alexey-tikhonov
Copy link
Member Author

Note: Covscan is green.

@alexey-tikhonov
Copy link
Member Author

alexey-tikhonov commented Feb 16, 2026

Argh... Processed a wrong PR :-/
I'll try to clean this up.

@SSSD SSSD deleted a comment from sssd-bot Feb 16, 2026
@alexey-tikhonov alexey-tikhonov force-pushed the hotpath-helpers-optimization branch from 0a3dcee to b8944ca Compare February 16, 2026 14:06
}
} else {
cache_ctx = talloc_new(NULL);
if (!cache_ctx) return NULL;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coding style: "Do not use !pointer"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

} else {
cache_ctx = talloc_new(NULL);
if (!cache_ctx) return NULL;
hret = hash_create(0, &lc_dom_name_cache, NULL, NULL);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi,

I wonder why there is no issue with the test running under valgrind. Since the hash table and it's entries are never freed shouldn't valgrind complain?

bye,
Sumit

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe because of

fun:_run_tests

?

Not sure.

@alexey-tikhonov
Copy link
Member Author

/gemini review

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces several performance improvements for hot path functions. The changes include using DEBUG_CONDITIONAL to reduce logging overhead, optimizing string-to-lowercase conversion by checking for already-lowercase ASCII strings, and adding a cache for lowercased domain names. While the optimizations are valuable, the new caching mechanism in usertools.c is not thread-safe and could lead to race conditions. I've provided a critical comment with a suggested fix to address this.

@alexey-tikhonov alexey-tikhonov added the coverity Trigger a coverity scan label Feb 17, 2026
@alexey-tikhonov
Copy link
Member Author

Note: Covscan is green.

@alexey-tikhonov alexey-tikhonov added Waiting for review and removed coverity Trigger a coverity scan labels Feb 17, 2026
Copy link
Contributor

@sumit-bose sumit-bose left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi,

thank you for the updates, I have no further comments, ACK.

bye,
Sumit

Both `perf` and manual measurement confirms ~6..8% perf gain
in the test case:
 - INITGROUPS lookup for a user that is a member of 5k groups,
   no groups were cached;
 - debug_level = 3
 - debug_microseconds = true

Note `debug_microseconds = true` - without this setting impact isn't
that dramatic.

Reviewed-by: Justin Stephenson <jstephen@redhat.com>
Reviewed-by: Sumit Bose <sbose@redhat.com>
In vast majority of cases strings are ascii and lowercase.
In other cases overhead added should be negligible.

Reviewed-by: Justin Stephenson <jstephen@redhat.com>
Reviewed-by: Sumit Bose <sbose@redhat.com>
This helper is heavily used, including in hot paths.

Since number of domains used is very limited, hash table used for caching
should be very small and lookup much more efficient as compared with
`sss_tc_utf8_str_tolower()`

Assisted-by: Claude Code (Opus 4.6)
Reviewed-by: Justin Stephenson <jstephen@redhat.com>
Reviewed-by: Sumit Bose <sbose@redhat.com>
@sssd-bot
Copy link
Contributor

The pull request was accepted by @alexey-tikhonov with the following PR CI status:


🟢 CodeQL (success)
🟢 osh-diff-scan:fedora-rawhide-x86_64:upstream (success)
🟢 rpm-build:centos-stream-10-x86_64:upstream (success)
🟢 rpm-build:fedora-42-x86_64:upstream (success)
🟢 rpm-build:fedora-43-x86_64:upstream (success)
🟢 rpm-build:fedora-44-x86_64:upstream (success)
🟢 rpm-build:fedora-rawhide-x86_64:upstream (success)
🟢 Analyze (target) / cppcheck (success)
🟢 Build / freebsd (success)
🟢 Build / make-distcheck (success)
🟢 ci / intgcheck (centos-10) (success)
🟢 ci / intgcheck (fedora-42) (success)
🟢 ci / intgcheck (fedora-43) (success)
🟢 ci / intgcheck (fedora-44) (success)
🟢 ci / intgcheck (fedora-45) (success)
🟢 ci / prepare (success)
🟢 ci / system (centos-10) (success)
🟢 ci / system (fedora-42) (success)
🟢 ci / system (fedora-43) (success)
🟡 ci / system (fedora-44) (in_progress)
🔴 ci / system (fedora-45) (failure)
➖ Coverity scan / coverity (skipped)
🟢 Static code analysis / codeql (success)
🟢 Static code analysis / pre-commit (success)
🟢 Static code analysis / python-system-tests (success)


There are unsuccessful or unfinished checks. Make sure that the failures are not related to this pull request before merging.

@sssd-bot sssd-bot force-pushed the hotpath-helpers-optimization branch from 8f8509f to 3ff1964 Compare February 17, 2026 15:49
@alexey-tikhonov alexey-tikhonov merged commit a5b77e4 into SSSD:master Feb 17, 2026
11 of 16 checks passed
@alexey-tikhonov alexey-tikhonov added the Performance Performance related patches label Feb 17, 2026
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 this pull request may close these issues.

4 participants