Skip to content

perf: optimize user-list, xauth, and xdmcp paths - #478

Open
GermanAizek wants to merge 1 commit into
ubuntu:mainfrom
GermanAizek:optimize
Open

perf: optimize user-list, xauth, and xdmcp paths#478
GermanAizek wants to merge 1 commit into
ubuntu:mainfrom
GermanAizek:optimize

Conversation

@GermanAizek

Copy link
Copy Markdown
Contributor

@jpeisach,

Using perf benchmarks from this PR (#477), we were able to carry out useful algorithmic optimization, namely:

User List

  • Replace O(N^2) per-entry g_list_insert_sorted() during passwd loading with O(1) prepend and a single O(N log N) g_list_sort() merge sort
  • Replace O(N^2) nested list traversals for existing and removed users with O(1) hash tables

Xauthority

  • Buffer all serialized records into a GByteArray in memory before writing to disk in a single atomic write() syscall, replacing up to 350 separate syscalls per update
  • Replace byte-by-byte loops in read_data() with block memcpy()
  • Replace O(N^2) g_list_append() with O(N) prepend + reverse

XDMCP

  • Replace byte-by-byte loops in read_data(), read_string(), write_data(), and write_string() with single-check block memcpy() operations

I post visual graphs my benchmarks on NUMA server motherboard 2x Xeon E5-2699v3 (Haswell 2014 year - 36 core 72 threads)

Two commits were compared:

  • integrate-benchmarks branch 4bf60ba (w/o optimizations)
  • optimize branch 1dd9c81

Attention on lookup_by_name from user list, change math algorithm speedup in 371x times !!!

image image image image

1. User List Optimization:
   - Replace O(N^2) per-entry g_list_insert_sorted() during passwd loading
     with O(1) prepend and a single O(N log N) g_list_sort() merge sort
   - Replace O(N^2) nested list traversals for existing and removed users
     with O(1) hash tables

2. Xauthority File Operations:
   - Buffer all serialized records into a GByteArray in memory before
     writing to disk in a single atomic write() syscall, replacing up to
     350 separate syscalls per update
   - Replace byte-by-byte loops in read_data() with block memcpy()
   - Replace O(N^2) g_list_append() with O(N) prepend + reverse

3. XDMCP Protocol Serialization:
   - Replace byte-by-byte loops in read_data(), read_string(), write_data(),
     and write_string() with single-check block memcpy() operations
@jpeisach

jpeisach commented Sep 4, 2026

Copy link
Copy Markdown
Collaborator

So the thing with the user lists.. I imagine most systems don't more than like, eight users at most? So I'm not sure how much this helps. Unless there are people using LightDM on systems with tons of users (in which this would be good)

I'm definitely interested in Xauthority and XDMCP optimizations.

I haven't decided what balance between space and time complexity we should have..

@GermanAizek

Copy link
Copy Markdown
Contributor Author

Unless there are people using LightDM on systems with tons of users

This is easy to calculate as a proportion.

371x - 1000 users lookup
37.1x - 100 users
3.7x - 10 users performance up

It’s actually more logical to use a hashtable.

@jpeisach

jpeisach commented Sep 5, 2026

Copy link
Copy Markdown
Collaborator

By that calculation.. for a one user system that's a slowdown (0.37)

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.

2 participants