We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi Everyone!
I have been working with P5 for a while now, but in my current project I'm working with large data sets for the first time. The FPS I'm getting when animating over 2000+ data points is not good, is there a way to improve upon this?
Thanks!
Answers
We'd have to see your code in order to determine if any optimisation is possible...
Share your code!
Some types of optimizations include:
Of course, if you are doing a lot of math for each point / object, there might be ways to optimize the math itself -- for example pre-calculating expensive shared terms and then sharing them....
Hi thanks for your answers already, sorry I forgot to add my code.. This is the content of my draw loop:
this.data
has about 2000 items in it.Well you could try pre-rendering the two different styles of ellipse into sprites. Not sure how much that improves things in p5js; but in theory it should help (as it should avoid a lot of repeated calculations). Maybe using WebGL might help?
I'm suspicious that there may be more to your code than you reveal here :P
Presumably there's some code affecting the dataPoint x and y coordinates each frame?
Well, I've made an optimized sketch based on what little code you've posted above. >-)
It pre-creates p5.Color instances via color() to be used w/ fill(). *-:)
https://p5js.org/reference/#/p5.Color
And skips invoking fill() if previous p5.Color is already the same as current 1. \m/
You can also view it running online @:
https://CodePen.io/GoSubRoutine/pen/aVRJQW/right?editors=001
And here's the full sample code: B-)
index.html:
sketch.js:
Thanks for your suggestion, GoToLoop! Sadly, when I increase the amount of items in the data array it gets just as slow :(
There is no way to optimize secret code that hasn't been shared. :(
1
comes before the others:https://Developer.Mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort
1
and the other not equal to1
. :ar!https://CodePen.io/GoSubRoutine/pen/aVRJQW/right?editors=001
index.html:
sketch.js: