-
py5 performance has been close enough to Processing's Java mode that I've never noticed any problems. However, while using load_pixels/update_pixels, py5's frame rate drops to between 1/3 and 1/4 of Processing. I got about same results compared to Processing's python mode, too. Is that something anyone else has noticed? Any suggestions for improving performance? I know this is a silly example, but I was just playing around and am curious. import py5
def setup():
py5.size(800, 800)
def draw():
c = py5.color(py5.random(255), py5.random(255), py5.random(255))
py5.load_pixels()
for i in range(py5.width*py5.height):
py5.pixels[i] = c
py5.update_pixels()
py5.run_sketch() |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
That makes me very happy to hear!
To answer your question, first I'd have to explain a bit about how py5 works. First, Python and Java don't share the same memory space, and second, there's a small performance penalty when a py5 method makes a call to java. Think of it as a toll you pay when going from Python to Java. The toll is small but it will accumulate if you do this in a loop, especially a loop for every pixel in the sketch. This code here: for i in range(py5.width*py5.height):
py5.pixels[i] = c is going to be slow because The And that extra step is using JPype's ability to create a numpy array that is backed by a Java Direct Buffer: https://jpype.readthedocs.io/en/latest/userguide.html#buffer-backed-numpy-arrays This means there is a performance improvement because Python can interact with the numpy array just as fast as any other numpy array because it is just a block of memory. It also means that I haven't quite answered your question though. I don't have suggestions for how to improve performance of that code other than you should use |
Beta Was this translation helpful? Give feedback.
That makes me very happy to hear!
To answer your question, first I'd have to explain a bit about how py5 works.
First, Python and Java don't share the same memory space, and second, there's a small performance penalty when a py5 method makes a call to java. Think of it as a toll you pay when going from Python to Java. The toll is small but it will accumulate if you do this in a loop, especially a loop for every pixel in the sketch.
This code here:
is going to be slow because
p…