KConfigIniBackend: Fix expensive detach in lookup
ClosedPublic

Authored by kfunk on Feb 18 2016, 11:55 PM.

Diff Detail

Branch
master
Lint
No Linters Available
Unit
No Unit Test Coverage
kfunk updated this revision to Diff 2396.Feb 18 2016, 11:55 PM
kfunk retitled this revision from to KConfigIniBackend: Fix expensive detach in lookup.
kfunk updated this object.
kfunk edited the test plan for this revision. (Show Details)
mdawson accepted this revision.Feb 19 2016, 2:36 AM
mdawson edited edge metadata.

LGTM.

Out of curiosity, why is the QHash detaching for you here? Or is this just a general fixup found with a linter? Either way, I'm happy to take it :)

This revision is now accepted and ready to land.Feb 19 2016, 2:36 AM
In D990#18912, @mdawson wrote:

LGTM.

Out of curiosity, why is the QHash detaching for you here? Or is this just a general fixup found with a linter? Either way, I'm happy to take it :)

Well, we're calling QHash::find on a non-const variable -> QHash::find detaches internally. Showed up in a Callgrind run.

kfunk closed this revision.Feb 19 2016, 12:11 PM

Pushed:

commit d9b3ce9038ed83d4967eb9a5111d57f6081a1394
Author: Kevin Funk <kfunk@kde.org>
Date: Fri Feb 19 00:53:48 2016 +0100

KConfigIniBackend: Fix expensive detach in lookup

Differential Revision: https://phabricator.kde.org/D990
In D990#18917, @kfunk wrote:
In D990#18912, @mdawson wrote:

LGTM.

Out of curiosity, why is the QHash detaching for you here? Or is this just a general fixup found with a linter? Either way, I'm happy to take it :)

Well, we're calling QHash::find on a non-const variable -> QHash::find detaches internally. Showed up in a Callgrind run.

Right, but looking at this function it looks like the QHash shouldn't have multiple copies which should prevent a detach in the first place. Thus I was curious what work load triggered the copies causing the detach.

kfunk added a comment.Feb 19 2016, 3:33 PM
In D990#18925, @mdawson wrote:
In D990#18917, @kfunk wrote:
In D990#18912, @mdawson wrote:

LGTM.

Out of curiosity, why is the QHash detaching for you here? Or is this just a general fixup found with a linter? Either way, I'm happy to take it :)

Well, we're calling QHash::find on a non-const variable -> QHash::find detaches internally. Showed up in a Callgrind run.

Right, but looking at this function it looks like the QHash shouldn't have multiple copies which should prevent a detach in the first place. Thus I was curious what work load triggered the copies causing the detach.

Indeed, you're right. I just noticed it calls QHash::detach, but doesn't reallocate (-> non-shared container). This patch won't harm, though: constFind/constEnd is still faster, doesn't check whether the container is shared to begin with.

In D990#18933, @kfunk wrote:
In D990#18925, @mdawson wrote:
In D990#18917, @kfunk wrote:
In D990#18912, @mdawson wrote:

LGTM.

Out of curiosity, why is the QHash detaching for you here? Or is this just a general fixup found with a linter? Either way, I'm happy to take it :)

Well, we're calling QHash::find on a non-const variable -> QHash::find detaches internally. Showed up in a Callgrind run.

Right, but looking at this function it looks like the QHash shouldn't have multiple copies which should prevent a detach in the first place. Thus I was curious what work load triggered the copies causing the detach.

Indeed, you're right. I just noticed it calls QHash::detach, but doesn't reallocate (-> non-shared container). This patch won't harm, though: constFind/constEnd is still faster, doesn't check whether the container is shared to begin with.

Ah, that makes a lot more sense. I'm still happy with the patch, thus why I hit accept. I was just curious how it came about :)