I'm working on a project at the moment with lots and lots of data, reading from a text file. The problem I'm having is really low framerates and then a slowdown - starting on 9fps and then getting slower and slower, tending towards 0fps. The points are being plotted with an opengl vertex buffer object (but this isn't the problem, the framerate was the same before I switched to opengl calls).
VisualVM blames my function drawData(). The code for the entire class that function is in is below. Is there a gaping problem here? Is a slowdown a sign of a bad loop or something, or does it just happen if it's all too much?
//This is GOD, the class for a Geospatially Overlaid Dataset.
PVector outputPVector = new PVector(int(pX), int(pY), int(pZ));
datasetSize is about 2,000,000 for one of the datasets (20 for the only other one currently in there). Is that just too much for a loop to run every frame? But then why does it get slower and slower? Or is it just graphics? surely 2,000,000 points should be able to render faster than this, especially when I'm using a vertex buffer object?
Removing the maths like you suggested gives me an increase in framerate to approximately 20fps, and, more importantly, it stays there! The biggest thing baffling me is why the framerate keeps slowing down. I guess then it has something to do with my returnGlobeCoordinate function (which gets calculated every frame, but I'll see if I can just calculate it once and then manipulate it all with matrix transformations. The colours do not change
Sorry what I just said is actually wrong! I restricted the number of points to 100,000, and that gave me a framerate of about 20. Regardless of the maths, 2,000,000 points still starts on a framerate of 9.03 and then starts dropping rapidly
Put everything in a GLModel and only set what changes. Don't set everything (positions, colors) on each frame like you are doing in your current code. You can change the position of the complete GLModel with no cost, if the GLModel itself (positions, colors) doesn't change. Even if/when some things change, you can do it. Just not everything on each draw. You are not only saving resources on the setting, but more importantly skipping all the calculations in the first place.
Try to work in radians everywhere, so you don't have to convert between degrees/radians. That is really wasteful calculation.
Your returnGlobeCoordinate() function does some costly calculations multiple times: pRadius * cos(lat)
A PVector is made from floats, so why turn all to int() when setting x,y,z? Seems wasteful.
The slowdown may be due to the fact you are creating millions of temporary PVector objects, which aren't removed by the garbage collector. Try setting all PVectors in a globally defined array. Then put the full array into the GLModel at once (I think this is possible in GLGraphics), instead of setting each xyz individually. So you have one single CPU-GPU transaction instead of 2 million. Perhaps this will help improve performance as well.