gsettings is fast

sometimes people will come up to me at a conference and one way or another mention that they are avoiding using gsettings because they need their app to start “really fast”. at uds for example, someone asked me “i should be using a keyfile for this, right?”.

gsettings has dconf as its backend. there are a couple of things that i assumed were common knowledge about dconf that surprised people when i told them. the main two things to note are that the on-disk dconf database is a hashtable that gets mmaped into your process and that reads (after the first read) typically involve zero system calls — just direct access to the hash table.

i still decided that it would be helpful to get a hold on some actual numbers here, though. i did some testing (nothing serious — but it gives a good idea of the ballpark figures involved here).

my methodology for measuring how long it takes to do something is this:

time (for i in `seq `1000` do; ./something; done > /dev/null) and dividing the ‘real’ time by 1000

running ‘/bin/true’ takes about 1.1ms
running a do-nothing program linked against libgio and calling g_type_init(): 2.2ms

when i went to benchmark gsettings i noticed that it was a bit slower than i thought. about 9ms to run the gsettings command line tool to “get” a setting. (for comparison, initialising gtk is 30ms and qt 350ms). still, i was wondering why it was so slow. it turns out that the largest part of that was that i was blocking on gdbus initialisation which (due to the chatty nature of the dbus protocol initialisation and the fact that dbus-daemon is a slow talker) takes quite a long time. gdbus needs to be initialised along with gsettings in order to add match rules for change notification.

i’ve fixed the backend so that we don’t block on gdbus initialisation anymore — it happens asynchronously and in another thread. those changes will land on master today. after the changes, running the gsettings commandline tool in ‘get’ mode takes about 4.2ms.

so for the record: the cost of initialising gsettings and reading a value out of dconf adds about 2ms to your program startup — less than 1/10th of the time it takes to initialise gtk and on the same order as the length of time it takes to spawn the process, load the shared libraries and call g_type_init().

3 thoughts on “gsettings is fast”

  1. This is awesome!

    How does this deal with /home shared over NFS with machines that have different architectures (i386 vs x86-64)?

    1. Marius: the offsets and pointers in the file are a fixed size of 32 bits. I can’t imagine anybody will have more than 4GB of settings. :)

  2. And what about little vs big endian. Do you make byteswapping for those offsets or is the file architecture dependent?

Comments are closed.