Help to improve sketch framerate, especially LiquidFun/PixelFlow components

I’m creating a display for a research study that will run on a MS Surface tablet that has an Intel i5-4300U and embedded graphics. When I run my current sketch on the tablet, I max out around 12fps, CPU runs around 20%, GPU runs around 100%, and RAM around 40%. I’d like to get the framerate up to at least 30 if not higher on that hardware, and I feel like it should be possible (I only render about 350 particles). It runs at around 28 fps on my laptop with dedicated GPU.

I’ve tested out bypassing various portions of my code, and it seems the major cause of my performance issues is just the particle simulation using LiquidFun. Too much is happening under the hood of that library for me to come up with any further ways to optimize that portion of my program. I’m also not sure if there’s any way to redirect processing that the GPU is trying to handle to the CPU instead, or something along those lines. I just came across threading and am trying to figure out if that can help me in any way. Any suggestions would be greatly appreciated.

Not sure how sketch folders are usually shared here, but mine is available here:
https://drive.google.com/open?id=1EuIN2E0Kednpw1tDvQgVs_Fxc72pLvOl
Click and drag the white slider to create motion.
This is my first Processing project, first Java project, and most significant programming project of any sort so far, so please bear with a bit of cumbersome code. Also, I haven’t made it nicely scalable, so it’ll only display properly on 1920x1080 or larger screens.

1 Like

Btw, if I haven’t asked a very answerable question, I’d love to know how I can fix that :slight_smile:

Other than that, it also seems that hardly anyone uses the LiquidFun and PixelFlow libraries even though they seem to be the only liquid simulation libraries out there!

@julianpb.c1 were you able to resolve this issue?

Unfortunately, how to optimize a very large LiquidFun + PixelFlow sketch, in general, is a very big ask.

I’d suggest starting with a much smaller particle emitter sketch and optimizing that, then building your extra features onto your optimized sketch.

Glancing at your sketch, I see several places to start – these are just ideas.

draw():

  1. don’t call textFont every frame.
  2. make your PGraphics2D canvas global – don’t declare a new one every frame
  3. you call world.applyTransform twice each frame. Is that intended?
  4. it looks like you are drawing the canvas, wiping most of it out with rect, then drawing again. Is there a less wasteful way to accomplish what you are doing with layout?
2 Likes

@jeremydouglass I have not resolved the issue yet, so really appreciate your reply!

Yeah, I knew I was asking a lot, but I didn’t know where else to turn. I did start with the LiquidFun and PixelFlow libraries by reverse engineering the examples and creating my own basic proofs-of-concept, but I didn’t pay much attention to framerate at that point.

I’ll work through the suggestions you’ve offered and see if that helps. I think some of what you’ve pointed out are artifacts from copying sections of code from the examples. I tried to trim everything I knew wasn’t needed, but my understanding was incomplete.

Thanks again!

1 Like