Mir

[performance] Mir spends 12%+ CPU time in get_hooked_symbol (libhybris-common) comparing strings

Bug #1343198 reported by Daniel van Vugt
12
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Mir
Invalid
Medium
Daniel van Vugt
libhybris (Ubuntu)
Fix Released
Medium
Daniel van Vugt

Bug Description

On the N4, Mir spends 12%+ CPU time in get_hooked_symbol (libhybris-common). Actually callgrind can't decide; it's somewhere between 12% and 46000% ;)

So it's big. Looking at the hybris code, there's a rather large bottleneck that's obvious: get_hooked_symbol does a linear search (many times) of a large list of strings using strcmp alone. That's why 22132 calls to get_hooked_symbol are yielding over 5 million calls to strcmp.

Upstream hybris appears to have been modified to use a cache/hashing instead of the ugly linear search we have.

Changed in libhybris (Ubuntu):
assignee: nobody → Daniel van Vugt (vanvugt)
status: New → In Progress
summary: - Mir spends 12%+ CPU time in get_hooked_symbol (libhybris-common)
+ [android] Mir spends 12%+ CPU time in get_hooked_symbol (libhybris-
+ common)
Revision history for this message
Daniel van Vugt (vanvugt) wrote : Re: [android] Mir spends 12%+ CPU time in get_hooked_symbol (libhybris-common)

Hmm, consistent profile results seem to tell me that the offending code is possibly only called on startup. But if the startup code accounts for 12% of the CPU time of something I left rendering for several minutes, it's still worth fixing.

Revision history for this message
Daniel van Vugt (vanvugt) wrote :

Here's a patch where I've converted the linear search into a binary search. Performance is improved by a factor of approximately 10.

Even if this code is only touched on startup, it's definitely worth having because this represents most of the startup time of the Mir server.

description: updated
summary: [android] Mir spends 12%+ CPU time in get_hooked_symbol (libhybris-
- common)
+ common) comparing strings when it should be rendering
Revision history for this message
Ubuntu Foundations Team Bug Bot (crichton) wrote : Re: [android] Mir spends 12%+ CPU time in get_hooked_symbol (libhybris-common) comparing strings when it should be rendering

The attachment "bsearch.patch" seems to be a patch. If it isn't, please remove the "patch" flag from the attachment, remove the "patch" tag, and if you are a member of the ~ubuntu-reviewers, unsubscribe the team.

[This is an automated message performed by a Launchpad user owned by ~brian-murray, for any issues please contact him.]

tags: added: patch
Revision history for this message
Ricardo Salveti (rsalveti) wrote :

Did you test the upstream implementation first to see if that is already enough for you? While I like the change you proposed, that would differ us from upstream, and the next rebase would mean dropping your change.

Revision history for this message
Daniel van Vugt (vanvugt) wrote :

I think hashing (upstream hybris) is a better idea and we should jump to that when possible. Although I just assumed we had no intention of rebasing given the significant diff. If we can then we should. I don't know what the performance diff to upstream is but upstream's hashing should possibly be even better than the bsearch.patch.

bsearch.patch is a short-term solution and long term we should rebase when possible.

summary: [android] Mir spends 12%+ CPU time in get_hooked_symbol (libhybris-
- common) comparing strings when it should be rendering
+ common) comparing strings
Changed in libhybris (Ubuntu):
importance: Undecided → Medium
summary: - [android] Mir spends 12%+ CPU time in get_hooked_symbol (libhybris-
+ [performance] Mir spends 12%+ CPU time in get_hooked_symbol (libhybris-
common) comparing strings
Changed in mir:
milestone: 0.6.0 → none
status: In Progress → Invalid
Changed in libhybris (Ubuntu):
assignee: Daniel van Vugt (vanvugt) → nobody
status: In Progress → Triaged
assignee: nobody → Daniel van Vugt (vanvugt)
Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package libhybris - 0.1.0+git20131207+e452e83-0ubuntu26

---------------
libhybris (0.1.0+git20131207+e452e83-0ubuntu26) utopic; urgency=medium

  [ Yu-Cheng Chou <email address hidden> ]
  * debian/control: fix typo in description (LP: #1259444)

  [ Daniel van Vugt ]
  * hooks: converting linear search into a binary search
    (LP: #1343198)
 -- Ricardo Salveti de Araujo <email address hidden> Thu, 14 Aug 2014 17:45:44 -0300

Changed in libhybris (Ubuntu):
status: Triaged → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.