mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-02-14 08:40:33 +01:00
Previously, setting or getting a variable required to scan all lines.
Note that frequently we would look up variables that didn't actually
exist, which we could only determine after searching the entire list.
Also, since we needed to handle having the same variable specified
multiple times (where the last occurrence wins), we always had to search
all keys and couldn't stop when finding the first key. Well, technically
we could have searched in reverse order for the getter, but that wasn't
done. For the setter we wanted to delete all but the last occurrences,
so to find them, we really had to search them all.
We want to support profiles with hundreds or thousands of addresses and routes.
This does not scale well.
Add an hash table to find the variables in constant time.
Test this commit and the parent commit:
$ git clean -fdx &&
CFLAGS=-O2 ./autogen.sh --with-more-asserts=0 &&
./tools/run-nm-test.sh -m src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh &&
perf stat -r 50 -B src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh 1>/dev/null
Before:
Performance counter stats for 'src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh' (50 runs):
330.94 msec task-clock:u # 0.961 CPUs utilized ( +- 0.33% )
0 context-switches:u # 0.000 K/sec
0 cpu-migrations:u # 0.000 K/sec
1,081 page-faults:u # 0.003 M/sec ( +- 0.07% )
1,035,923,116 cycles:u # 3.130 GHz ( +- 0.29% )
1,800,084,022 instructions:u # 1.74 insn per cycle ( +- 0.01% )
362,313,301 branches:u # 1094.784 M/sec ( +- 0.02% )
6,259,421 branch-misses:u # 1.73% of all branches ( +- 0.13% )
0.34454 +- 0.00116 seconds time elapsed ( +- 0.34% )
Now:
Performance counter stats for 'src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh' (50 runs):
329.78 msec task-clock:u # 0.962 CPUs utilized ( +- 0.39% )
0 context-switches:u # 0.000 K/sec
0 cpu-migrations:u # 0.000 K/sec
1,084 page-faults:u # 0.003 M/sec ( +- 0.05% )
1,036,130,698 cycles:u # 3.142 GHz ( +- 0.13% )
1,799,851,979 instructions:u # 1.74 insn per cycle ( +- 0.01% )
360,374,338 branches:u # 1092.756 M/sec ( +- 0.01% )
6,160,796 branch-misses:u # 1.71% of all branches ( +- 0.08% )
0.34287 +- 0.00133 seconds time elapsed ( +- 0.39% )
So, not much difference. But this is not surprising, because test-ifcfg-rh loads and
writes predominantly ifcfg files with few variables. The difference should be visible
when having large files.
|
||
|---|---|---|
| .. | ||
| devices | ||
| dhcp | ||
| dns | ||
| dnsmasq | ||
| initrd | ||
| ndisc | ||
| platform | ||
| ppp | ||
| settings | ||
| supplicant | ||
| systemd | ||
| tests | ||
| vpn | ||
| main-utils.c | ||
| main-utils.h | ||
| main.c | ||
| meson.build | ||
| NetworkManagerUtils.c | ||
| NetworkManagerUtils.h | ||
| nm-act-request.c | ||
| nm-act-request.h | ||
| nm-active-connection.c | ||
| nm-active-connection.h | ||
| nm-audit-manager.c | ||
| nm-audit-manager.h | ||
| nm-auth-manager.c | ||
| nm-auth-manager.h | ||
| nm-auth-subject.c | ||
| nm-auth-subject.h | ||
| nm-auth-utils.c | ||
| nm-auth-utils.h | ||
| nm-checkpoint-manager.c | ||
| nm-checkpoint-manager.h | ||
| nm-checkpoint.c | ||
| nm-checkpoint.h | ||
| nm-config-data.c | ||
| nm-config-data.h | ||
| nm-config.c | ||
| nm-config.h | ||
| nm-connectivity.c | ||
| nm-connectivity.h | ||
| nm-core-utils.c | ||
| nm-core-utils.h | ||
| nm-dbus-manager.c | ||
| nm-dbus-manager.h | ||
| nm-dbus-object.c | ||
| nm-dbus-object.h | ||
| nm-dbus-utils.c | ||
| nm-dbus-utils.h | ||
| nm-dcb.c | ||
| nm-dcb.h | ||
| nm-dhcp4-config.c | ||
| nm-dhcp4-config.h | ||
| nm-dhcp6-config.c | ||
| nm-dhcp6-config.h | ||
| nm-dispatcher.c | ||
| nm-dispatcher.h | ||
| nm-firewall-manager.c | ||
| nm-firewall-manager.h | ||
| nm-hostname-manager.c | ||
| nm-hostname-manager.h | ||
| nm-iface-helper.c | ||
| nm-ip4-config.c | ||
| nm-ip4-config.h | ||
| nm-ip6-config.c | ||
| nm-ip6-config.h | ||
| nm-keep-alive.c | ||
| nm-keep-alive.h | ||
| nm-logging.c | ||
| nm-logging.h | ||
| nm-manager.c | ||
| nm-manager.h | ||
| nm-netns.c | ||
| nm-netns.h | ||
| nm-pacrunner-manager.c | ||
| nm-pacrunner-manager.h | ||
| nm-policy.c | ||
| nm-policy.h | ||
| nm-proxy-config.c | ||
| nm-proxy-config.h | ||
| nm-rfkill-manager.c | ||
| nm-rfkill-manager.h | ||
| nm-session-monitor.c | ||
| nm-session-monitor.h | ||
| nm-sleep-monitor.c | ||
| nm-sleep-monitor.h | ||
| nm-test-utils-core.h | ||
| nm-types.h | ||
| org.freedesktop.NetworkManager.conf | ||