ngerritsen / timiks

GNU General Public License v3.0
13 stars 5 forks source link

Performance of Archive with many values #31

Closed Jobarion closed 4 years ago

Jobarion commented 4 years ago

Right now, the archive view becomes unresponsive when many values are displayed in one graph, sometimes for a few minutes. The problem seems to be the calculation of stats So far I have been able to identify two issues:

A suggestion for generateArr:

function generateArr(n) {
  let arr = new Array(n);

  for (let i = 0; i < n; i++) {
    arr[i] = i;
  }

  return arr;
}

See https://jsperf.com/generatearr/1 for a comparison.

For the moving average calculation, see https://jsperf.com/moving-average-trimmed/1 for an example. The new method would be faster by a factor of 2. It's considerably more complicated, but I think it's worth it. Note that I already used the improved generateArr function for the old method.

ngerritsen commented 4 years ago

Wow nice analysis. Bit occupied right now but I will look into it!

Jobarion commented 4 years ago

I just wanted to check if you were open to fix this :) In that case I'll create a PR, that hopefully simplifies integration and testing for you.

ngerritsen commented 4 years ago

I just wanted to check if you were open to fix this :) In that case I'll create a PR, that hopefully simplifies integration and testing for you.

That would be great!

ngerritsen commented 4 years ago

I found a slightly simpler way of improving the performance of the generateArr function. As copying the array was the issue, I changed that part, according to jsperf it is a bit faster even. https://github.com/ngerritsen/timiks/commit/71e5e514d823e53fa48315d72780d7374842f62e

ngerritsen commented 4 years ago

The PR is merged, thanks for the effort!