Merge lp:~ahayzen/music-app/remix-fix-1386628-slow-trackclicked into lp:music-app/remix

Proposed by Andrew Hayzen
Status: Merged
Approved by: Victor Thompson
Approved revision: 715
Merged at revision: 717
Proposed branch: lp:~ahayzen/music-app/remix-fix-1386628-slow-trackclicked
Merge into: lp:music-app/remix
Diff against target: 49 lines (+9/-12)
2 files modified
meta-database.js (+3/-10)
music-app.qml (+6/-2)
To merge this branch: bzr merge lp:~ahayzen/music-app/remix-fix-1386628-slow-trackclicked
Reviewer Review Type Date Requested Status
Victor Thompson Approve
Ubuntu Phone Apps Jenkins Bot continuous-integration Approve
Review via email: mp+239905@code.launchpad.net

Commit message

* Optimise the addQueueList transaction

Description of the change

* Optimise the addQueueList transaction

This reduces the overall time from the track being clicking to playing from ~2.4s -> 1.1s on my N4. The remaining time is split up over the following:
* model.clear() ~75ms
* addQueueFromModel() ~325ms (110ms going to addQueueList [was 1000ms+ before] the rest append to trackQueue)
* MediaPlayer.play() ~450ms
* pushNowPlaying() ~300ms

I attempted to use a worker script to speed up the appending to trackQueue, but that actually resulted in slow down. The next areas of investigation should probably be why MediaPlayer.play() takes 450ms (we should compare on desktop as well as device [note MediaPlayer takes 175ms to create as well]) and investigate incubateObject for pushNowPlaying(). Maybe the page could be incubating while we are pushing to the model?

TL;DR; this MP reduces the trackClicked time by ~2.4->1.1 in a certain scenario but there are still areas for improvement.

To post a comment you must log in.
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Victor Thompson (vthompson) wrote :

Could we not call the array "model" inside the addQueueList() function... it's misleading.

review: Needs Fixing
715. By Andrew Hayzen

* Rename variable from model to items

Revision history for this message
Victor Thompson (vthompson) wrote :

LGTM!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'meta-database.js'
2--- meta-database.js 2014-10-28 03:32:01 +0000
3+++ meta-database.js 2014-10-29 01:20:43 +0000
4@@ -56,19 +56,12 @@
5 );
6 }
7
8-function addQueueList(model) {
9+function addQueueList(items) {
10 var db = getDatabase();
11- var res="";
12
13 db.transaction(function(tx) {
14-
15- for (var i = 0; i < model.count; i++) {
16- var rs = tx.executeSql('INSERT OR REPLACE INTO queue (ind, filename) VALUES (?,?);', [i, model.get(i).filename]);
17- if (rs.rowsAffected > 0) {
18- res = "OK";
19- } else {
20- res = "Error";
21- }
22+ for (var i = 0; i < items.length; i++) {
23+ tx.executeSql('INSERT OR REPLACE INTO queue (ind, filename) VALUES (?,?);', [i, items[i].filename]);
24 }
25 }
26 );
27
28=== modified file 'music-app.qml'
29--- music-app.qml 2014-10-28 03:39:30 +0000
30+++ music-app.qml 2014-10-29 01:20:43 +0000
31@@ -608,12 +608,16 @@
32 model = model.linkLibraryListModel;
33 }
34
35+ var items = []
36+
37 for (var i=0; i < model.rowCount; i++) {
38- trackQueue.model.append(model.get(i, model.RoleModelData));
39+ items.push(model.get(i, model.RoleModelData))
40+
41+ trackQueue.model.append(items[i]);
42 }
43
44 // Add model to queue storage
45- Library.addQueueList(trackQueue.model);
46+ Library.addQueueList(items);
47 }
48
49 // Converts an duration in ms to a formated string ("minutes:seconds")

Subscribers

People subscribed via source and target branches