[UDisks DeviceBackend] Slightly optimize
AbandonedPublic

Authored by broulik on Nov 28 2017, 10:41 AM.

Details

Reviewers
davidedmundson
Group Reviewers
Frameworks
Summary
  • Avoid double lookup (contains+value)
  • Just delete take() instead of contains+value+remove+delete
  • Delay connecting to DBus change signals (this is done in other places, too)
  • Use range-for
  • Use iterator's key() instead of creating temporary keys() list
Test Plan

It creates 22 device backends on Dolphin startup, delaying connecting to later saves 1.5ms startup in total.

  • Devices still properly populated
  • Mounting and unmounting devices still updates places list live

Diff Detail

Repository
R245 Solid
Lint
Lint Skipped
Unit
Unit Tests Skipped
broulik created this revision.Nov 28 2017, 10:41 AM
Restricted Application added a project: Frameworks. ยท View Herald TranscriptNov 28 2017, 10:41 AM
broulik requested review of this revision.Nov 28 2017, 10:41 AM
apol added a subscriber: apol.Nov 28 2017, 11:26 AM
apol added inline comments.
src/solid/devices/backends/udisks2/udisksdevicebackend.cpp
67

What do we gain by delaying dbus connection?

broulik added inline comments.Dec 1 2017, 10:05 AM
src/solid/devices/backends/udisks2/udisksdevicebackend.cpp
67

Similar code in different place had a comment

// Delay connecting to DBus signals to avoid the related time penalty
// in hot paths such as predicate matching
davidedmundson added inline comments.Dec 1 2017, 10:23 AM
src/solid/devices/backends/udisks2/udisksdevicebackend.cpp
67

Never trust existing code.

You're not going to get to process DBus events until we hit the event queue anyway.

broulik abandoned this revision.Apr 24 2018, 2:58 PM

The important stuff (double/triple lookup) was already committed elsewhere and the rest is just minor coding style stuff

bruns added a subscriber: bruns.Apr 24 2018, 3:01 PM
bruns added inline comments.Apr 24 2018, 4:33 PM
src/solid/devices/backends/udisks2/udisksdevicebackend.cpp
67

Its also clearly racy.

You have to connect to the signals before initializing the list of interfaces. Otherwise the following lets you end up in an undefined state:

  1. you send introspection query
  2. the Daemon sends the respone
  3. the Daemon sends an InterfacesAdded
  4. you process the introspection response
  5. you drop the InterfacesAdded signal
  6. you connect the signals