After 6000 notes app becomes laggy
Graham42 opened this issue · comments
Using sheetmusictutor.com local data is saved between page visits. Over a longer period of time the amount of data continues to grow. At over 6000 notes played the webapp becomes sluggish and the time from playing a note until it being recognized increases to a point where it's not very usable.
I'm glad to hear that somebody is using the app so intensively :) The code for the statistics is quite inefficient (all the data is serialized and unserialized on each event if I remember correctly) and probably easy to optimize. Unfortunately, I don't have time for this at the moment. I'd be happy to accept a PR for this.
A quick workaround would obviously be to clear the local storage or to remove events older than X if you want to keep some of your statistics.
I cleared local storage and that's a good enough work around for me.
For fun I ran some profiling using Chrome and found that the current bottleneck is in LevelService.assessLevel
specifically where the code creates the unfoldedEvents
(level_service.js#L107).
I played around with this but it always comes back to the event being copied for each key
in event.keys
I think the real solution is to restructure the statistics so that a separate event is stored per key. Just wanted to get your thoughts if you have any before going down this path.
If curious, here's how I generated some test data
var start = new Date();
var count = start.getTime();
var result = [];
for (let i = 0; i < 7000; i++) {
result.push({
success: (Math.random() > 0.2),
keys: ["e/4"],
time: (500 + Math.floor(Math.random() * 1000)),
keySignature: "C",
date: JSON.stringify(new Date(count -= 3000)),
})
};
result.reverse()
localStorage.setItem('pianoTrainerStatistics', result)
Thank you very much! I'll close this issue, since #11 seems to have fixed it.