diff options
author | Florrie <towerofnix@gmail.com> | 2018-12-15 00:56:51 -0400 |
---|---|---|
committer | Florrie <towerofnix@gmail.com> | 2018-12-15 00:56:51 -0400 |
commit | 9a4f04fbd3233fe2711b2cf5d11c4baa46e78b89 (patch) | |
tree | b205f597682faa25010064a1a8ac3bdc5d46594e /index.js | |
parent | e618ee3004dc8bf8276b6bee9b0280ce6ca39119 (diff) |
Dramatically optimize perf of large playlists
Now you can browse modland.json at your leisure, without the fear of waiting 10 seconds every time you so much as move your cursor!
Diffstat (limited to 'index.js')
-rwxr-xr-x | index.js | 42 |
1 files changed, 31 insertions, 11 deletions
diff --git a/index.js b/index.js index 15392bd..f1073e0 100755 --- a/index.js +++ b/index.js @@ -82,23 +82,47 @@ async function main() { root.fixAllLayout() }) + const loadPlaylists = async () => { + for (let i = 2; i < process.argv.length; i++) { + await appElement.handlePlaylistSource(process.argv[i], true) + } + } + + const loadPlaylistPromise = loadPlaylists() + if (process.argv.includes('--stress-test')) { + await loadPlaylistPromise + const w = 80 const h = 40 flushable.resizeScreen({lines: w, cols: h}) root.w = w root.h = h root.fixAllLayout() - const start = Date.now() - let n = 0 - while (Date.now() < start + 1000) { + + const stress = func => { + const start = Date.now() + let n = 0 + while (Date.now() < start + 1000) { + func() + n++ + } + return n + } + + const nRenderAndFlush = stress(() => { root.renderTo(flushable) flushable.flush() - n++ - } + }) + + const nFixAllLayout = stress(() => { + root.fixAllLayout() + }) + + process.stdout.write(ansi.cleanCursor() + ansi.clearScreen() + '\n') + console.log('# of times we can render & flush:', nRenderAndFlush) + console.log('# of times we can fix all layout:', nFixAllLayout) - console.log(ansi.clearScreen() + ansi.cleanCursor()) - console.log('# of times ran:', n) process.exit(0) return @@ -108,10 +132,6 @@ async function main() { root.renderTo(flushable) flushable.flush() }, 50) - - for (let i = 2; i < process.argv.length; i++) { - await appElement.handlePlaylistSource(process.argv[i], true) - } } main().catch(err => { |