From e4d77679dcd0d13e498ef510ea99555a0a1ec1e4 Mon Sep 17 00:00:00 2001 From: Cory McWilliams Date: Thu, 27 Jan 2022 01:17:22 +0000 Subject: [PATCH] Show a breakdown of timing. git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3797 ed5197a5-7fde-0310-b194-c3ffbd925b24 --- apps/cory/index.json | 2 +- apps/cory/index/app.js | 22 +++++++++++++++++++++- apps/cory/index/index.html | 7 ++++++- apps/cory/index/tf.js | 2 ++ 4 files changed, 30 insertions(+), 3 deletions(-) diff --git a/apps/cory/index.json b/apps/cory/index.json index b3b94b55..9cf2ae61 100644 --- a/apps/cory/index.json +++ b/apps/cory/index.json @@ -1 +1 @@ -{"type":"tildefriends-app","files":{"app.js":"&MctA7OZPTgdTZnlSwKMJTYjZg+S8blg4VdO/njxN0QU=.sha256","index.html":"&eY9aBHpnmbMTXXnbzv9gxxXvJp8O5NpcqulQxdnsW/s=.sha256","vue-material.js":"&K5cdLqXYCENPak/TCINHQhyJhpS4G9DlZHGwoh/LF2g=.sha256","tf-user.js":"&DdJwZYEo7AqFyutYMvEjykoVXxdHVog0UXye6Sbo0TU=.sha256","tf-message.js":"&3dPiSNYjoJE3zn1oTT1SBhbvkW9MHr7ZUDxUJiBI1Ss=.sha256","tf.js":"&7hS4IikdZdlZDiMlZ1UK9Wf6rdOwceevKGPBRlhDZ68=.sha256","commonmark.min.js":"&EP0OeR9zyLwZannz+0ga4s9AGES2RLvvIIQYHqqV6+k=.sha256","vue.js":"&g1wvA+yHl1sVC+eufTsg9If7ZeVyMTBU+h0tks7ZNzE=.sha256","vue-material-theme-default-dark.css":"&RP2nr+2CR18BpHHw5ST9a5GJUCOG9n0G2kuGkcQioWE=.sha256","vue-material.min.css":"&kGbUM2QgFSyHZRzqQb0b+0S3EVIlZ0AXpdiAVjIhou8=.sha256","roboto.css":"&jJv43Om673mQO5JK0jj7714s5E+5Yrf82H6LcDx7wUs=.sha256","material-icons.css":"&a28PdcVvgq/DxyIvJAx/e+ZOEtOuHnr3kjLWKyzH11M=.sha256","tf-shared.js":"&+qPP3g4CAUlkt8K4iBCZ+F5Fy6N7fu6MggvSVss2juE=.sha256"}} \ No newline at end of file +{"type":"tildefriends-app","files":{"app.js":"&mDHhPk+YJm9K32UmO6WNUoJGM1tX4Dx7GIMjLvyurXg=.sha256","index.html":"&WJSszNEPd6ypJkfTUu/YHSDvU8VZrAHvyRmzNoZBPb0=.sha256","vue-material.js":"&K5cdLqXYCENPak/TCINHQhyJhpS4G9DlZHGwoh/LF2g=.sha256","tf-user.js":"&DdJwZYEo7AqFyutYMvEjykoVXxdHVog0UXye6Sbo0TU=.sha256","tf-message.js":"&3dPiSNYjoJE3zn1oTT1SBhbvkW9MHr7ZUDxUJiBI1Ss=.sha256","tf.js":"&DQtOS/nh5/a6QlqNrIb5Zi3Bz4pn3MBe5peRkwLZuyA=.sha256","commonmark.min.js":"&EP0OeR9zyLwZannz+0ga4s9AGES2RLvvIIQYHqqV6+k=.sha256","vue.js":"&g1wvA+yHl1sVC+eufTsg9If7ZeVyMTBU+h0tks7ZNzE=.sha256","vue-material-theme-default-dark.css":"&RP2nr+2CR18BpHHw5ST9a5GJUCOG9n0G2kuGkcQioWE=.sha256","vue-material.min.css":"&kGbUM2QgFSyHZRzqQb0b+0S3EVIlZ0AXpdiAVjIhou8=.sha256","roboto.css":"&jJv43Om673mQO5JK0jj7714s5E+5Yrf82H6LcDx7wUs=.sha256","material-icons.css":"&a28PdcVvgq/DxyIvJAx/e+ZOEtOuHnr3kjLWKyzH11M=.sha256","tf-shared.js":"&+qPP3g4CAUlkt8K4iBCZ+F5Fy6N7fu6MggvSVss2juE=.sha256"}} \ No newline at end of file diff --git a/apps/cory/index/app.js b/apps/cory/index/app.js index c05892a9..9c3a8d18 100644 --- a/apps/cory/index/app.js +++ b/apps/cory/index/app.js @@ -305,13 +305,17 @@ core.register('onConnectionsChanged', async function() { }); async function refresh(selected) { + var timing = []; + timing.push({name: 'start', time: new Date()}); g_following_cache = {}; g_followers_cache = {}; g_following_deep_cache = {}; await app.postMessage({clear: true}); var whoami = await ssb.whoami(); var db = await database("ssb"); + timing.push({name: 'init', time: new Date()}); var all_followed = await followingDeep(db, [whoami], 2); + timing.push({name: 'all_followed', time: new Date()}); if (selected) { g_selected = selected; } else { @@ -324,6 +328,7 @@ async function refresh(selected) { ssb.connections().then(connections => app.postMessage({connections: connections})), core.apps().then(apps => app.postMessage({apps: apps})), ]); + timing.push({name: 'core', time: new Date()}); var ids; if (selected && selected.length == 1 && selected[0].startsWith('%')) { var m = await getPosts(db, selected); @@ -332,7 +337,9 @@ async function refresh(selected) { } else { ids = await getRecentPostIds(db, whoami, g_selected, k_posts_max); } + timing.push({name: 'get_post_ids', time: new Date()}); var posts = await getPosts(db, ids); + timing.push({name: 'get_posts', time: new Date()}); var roots = posts.map(function(x) { try { return JSON.parse(x.content).root; @@ -343,11 +350,24 @@ async function refresh(selected) { var have = new Set(posts.map(x => x.id)); roots = [...new Set(roots)].filter(x => x && !have.has(x)); var all_posts = [].concat(posts, await getPosts(db, roots)); + timing.push({name: 'get_root_posts', time: new Date()}); await Promise.all(all_posts.map(x => app.postMessage({message: x}))); + timing.push({name: 'send_posts', time: new Date()}); await Promise.all(all_followed.map(id => getAbout(db, id).then(results => app.postMessage({user: {user: id, about: results}})))); + timing.push({name: 'about', time: new Date()}); await Promise.all(all_followed.map(id => getVotes(db, id).then(results => results.length ? app.postMessage({votes: results}) : null))); + timing.push({name: 'votes', time: new Date()}); await Promise.all(all_followed.map(id => following(db, id).then(results => app.postMessage({following: {id: id, users: [...results]}})))); - await app.postMessage({ready: true}); + timing.push({name: 'following', time: new Date()}); + + var times = {}; + var previous = null; + for (let t of timing) { + times[t.name] = t.time - (previous || t).time; + previous = t; + } + + await app.postMessage({ready: true, times: times}); } ssb.addEventListener('message', async function(id) { diff --git a/apps/cory/index/index.html b/apps/cory/index/index.html index 1f549f00..7deac997 100644 --- a/apps/cory/index/index.html +++ b/apps/cory/index/index.html @@ -47,7 +47,12 @@ Welcome, . - Loaded in {{load_time}} seconds. + + Loaded in {{load_time}} seconds. + +
{{key}}: {{times[key] / 1000.0}} s
+
+
What's up?
diff --git a/apps/cory/index/tf.js b/apps/cory/index/tf.js index c4d3ff78..8e1f33de 100644 --- a/apps/cory/index/tf.js +++ b/apps/cory/index/tf.js @@ -21,6 +21,7 @@ var g_data = { edit_profile_description: null, load_time: null, post_text: null, + times: {}, }; var g_load_start = new Date(); @@ -134,6 +135,7 @@ function processMessages() { } else if (key == 'ready') { g_data.load_time = (new Date() - g_load_start) / 1000; g_data.loading = false; + g_data.times = event.data.times; } else if (key == 'unread') { g_data.unread += event.data.unread; } else if (key == 'hash') {