Thanks!
X
Paypal
Github sponsorship
Patreon

articles

New sysinfo version (huge performance improvements!)

Hi everyone!

It's (very) rare that I make a post about a new sysinfo version but I think this one is definitely worth it!

Some what about those performance improvements?

Like the title states, this new version comes with great performance improvements. We're talking about 3x faster on macos, 2x faster on linux and 3x faster on windows (the benchmarks are at the end of the post).

So how do I achieve this? In one word: rayon. The refresh_processes method was (very) slow (and still is) because we had to go through all processes, on by one and perform huge computations on each. But all these computations could be run in parallel so why not? That's where rayon kicks in!

The only trouble was that I couldn't modify the hashmap directly in the method, any new process had to be added into after the parallel iteration. But it's still a few times faster because all computations are run in parallel (I really love this word).

In addition to this, the mac version received a bit more love than the two others. In addition to the rayon add, I replaced some multiplication/division operations with bits shifting when I could (so on power 2 numbers).

The Linux version also got a bit of extra attention but nothing significant. It is more like a trial. This version is very slow because of I/O. Most system information I'm looking for are stored into "files" (not really files but you interact with them just like you would with normal files). And which means files means parsing. I think that's where most optimizations remain to be performed. More to come soon!

Now what about the Windows version? I have to admit that I don't know much about the Windows OS. Therefore, some obvious/easy optimizations might be possible, but for the moment, didn't find any. I think this is the version which will get the biggest performance improvements of all. But first, I need to read a lot more about how it works and how to get information I want more efficiently.

This new release was the first step to even more optimizations. This is very funny to try to always think of new ways to get and compute information. Sometimes, some syscalls might be better than some code optimizations. You just need to discover them, and this is what I'll try to do!

If you want to take a look at the pull request, here it is: https://github.com/GuillaumeGomez/sysinfo/pull/117.

Benchmarks

Now let's take a look to the benchmarks. Please note that the 3 computers are very different in term of components, which might explain such differences:

Mac

Before:

test bench_new                ... bench:   6,277,338 ns/iter (+/- 776,626)
test bench_refresh_all        ... bench:   2,777,395 ns/iter (+/- 792,563)
test bench_refresh_disk_lists ... bench:     252,386 ns/iter (+/- 27,681)
test bench_refresh_disks      ... bench:         616 ns/iter (+/- 270)
test bench_refresh_network    ... bench:      44,931 ns/iter (+/- 10,870)
test bench_refresh_process    ... bench:       4,250 ns/iter (+/- 132)
test bench_refresh_processes  ... bench:   1,130,398 ns/iter (+/- 34,410)
test bench_refresh_system     ... bench:     701,725 ns/iter (+/- 167,934)

After:

test bench_new                ... bench:   3,998,801 ns/iter (+/- 233,505)
test bench_refresh_all        ... bench:   1,278,118 ns/iter (+/- 143,394)
test bench_refresh_disk_lists ... bench:     252,440 ns/iter (+/- 15,763)
test bench_refresh_disks      ... bench:         630 ns/iter (+/- 249)
test bench_refresh_network    ... bench:      44,671 ns/iter (+/- 1,680)
test bench_refresh_process    ... bench:       4,465 ns/iter (+/- 2,300)
test bench_refresh_processes  ... bench:     446,773 ns/iter (+/- 63,277)
test bench_refresh_system     ... bench:     562,777 ns/iter (+/- 81,104)

Linux

Before:

test bench_new                ... bench:  56,906,064 ns/iter (+/- 2,197,002)
test bench_refresh_all        ... bench:  11,413,569 ns/iter (+/- 855,971)
test bench_refresh_disk_lists ... bench:      76,971 ns/iter (+/- 9,166)
test bench_refresh_disks      ... bench:      42,398 ns/iter (+/- 6,330)
test bench_refresh_network    ... bench:      14,234 ns/iter (+/- 1,325)
test bench_refresh_process    ... bench:         200 ns/iter (+/- 8)   <== this was a bug
test bench_refresh_processes  ... bench:  10,757,594 ns/iter (+/- 947,818)
test bench_refresh_system     ... bench:      86,459 ns/iter (+/- 7,633)

After:

test bench_new                ... bench:  12,685,631 ns/iter (+/- 4,123,168)
test bench_refresh_all        ... bench:   5,440,071 ns/iter (+/- 1,286,536)
test bench_refresh_disk_lists ... bench:      94,706 ns/iter (+/- 6,656)
test bench_refresh_disks      ... bench:      43,847 ns/iter (+/- 12,716)
test bench_refresh_network    ... bench:      14,833 ns/iter (+/- 1,227)
test bench_refresh_process    ... bench:       7,248 ns/iter (+/- 844)
test bench_refresh_processes  ... bench:   4,035,119 ns/iter (+/- 759,456)
test bench_refresh_system     ... bench:      86,421 ns/iter (+/- 5,897)

Windows

Before:

test bench_new                ... bench: 591,527,220 ns/iter (+/- 263,498,337)
test bench_refresh_all        ... bench: 356,635,315 ns/iter (+/- 64,393,390)
test bench_refresh_disk_lists ... bench:     157,257 ns/iter (+/- 20,659)
test bench_refresh_disks      ... bench:      45,767 ns/iter (+/- 20,894)
test bench_refresh_network    ... bench:         487 ns/iter (+/- 39)
test bench_refresh_process    ... bench:       8,458 ns/iter (+/- 312)
test bench_refresh_processes  ... bench: 327,626,625 ns/iter (+/- 39,483,199)
test bench_refresh_system     ... bench:       1,336 ns/iter (+/- 155)

After:

test bench_new                ... bench: 310,174,084 ns/iter (+/- 182,279,794)
test bench_refresh_all        ... bench: 123,698,474 ns/iter (+/- 52,320,355)
test bench_refresh_disk_lists ... bench:     152,887 ns/iter (+/- 16,594)
test bench_refresh_disks      ... bench:      45,967 ns/iter (+/- 5,002)
test bench_refresh_network    ... bench:         485 ns/iter (+/- 16)
test bench_refresh_process    ... bench:       1,705 ns/iter (+/- 108)
test bench_refresh_processes  ... bench: 122,890,190 ns/iter (+/- 5,728,812)
test bench_refresh_system     ... bench:       1,304 ns/iter (+/- 94)
Posted on the 09/04/2018 at 23:30 by @GuillaumeGomez

Previous article

Rust+GNOME Hackfest in Madrid

Next article

Using macro to generate generic docs?
Back to articles list
RSS feedRSS feed