Having read some of the source code, I’d say Processing has ‘enough’ optimization. The rest is upto the person using it.
Perhaps the best I can do to contribute to this topic is provide some advice:
- Please research about the concept of stack and heap memory allocations. The concept of memory allocation is used mostly by
C++ programmers, but it is useful regardless of the language you use.
Mostly, it is about preventing declaring new objects - it is fine to write code such as
ClassName objectName = someOtherObjectName;, but using the
new keyword inside functions/methods that you or somebody else might call very often (such as Processing’s
draw() function/method), is a consumer of performance. Please declare such variables in a namespace just outside such functions, where it is easier to read and change their values.
JIT-compiler might already be aware of such issues, but it is better for us to not cause such issues in the first place!
DSA classes can often give you better methods for doing certain things, use those.
For the case of using Processing specifically, you may want to look into utilities such as the
PShape class, …and avoid heavy ones such as
Lastly, it is just a better choice to spend time learning to write optimized code whenever possible.
Spend time with making test projects to measure your code’s performance, and compare different methods. It is helpful to use the internet for knowledge on such matters. Many stackoverflow posts have made such matters clear.
I myself have the [bad] habit of thinking of possible optimizations in code before actually writing it, which is not considered good by the software industry (older members, such as those who write
C++, or graphics applications like us, still consider this a very important skill). However, yes, it is important to spend time optimizing your code as soon as you’re done writing it, no matter you are using code to make art, or some heavy application (such as a game). This must be made into a habit.
Do not waste time thinking of every little optimization, though, the software industry, and legendary computer scientists such as Sir Donald Knuth (I hope that was the correct name!) have taught us not to spend too much time optimizing for every little thing; as Sir Donald Knuth said, a programmer, will only need to optimize so much, for only
3% of their entire career!
…also, in computer graphics, we often have situations we can do nothing about - needing seperate loops for updating different aspects of a list of objects, where you require all objects of a list to already have received updates, and situations where your program has graphics that need to be displayed on a screen that could change its size, and so you need to resize them according to the new dimensions of the screen (although techniques such as projection already do this for us, such situations can arrive sometimes) - in such cases, people who care about optimization prefer to make variables with such data cached and updated only when the screen size changes (imagine making a set of variables such as
pheight!). However, it is often not possible to maintain so many variables, and doing simple math with variables you might already have - such as those holding the coordinates of the center, is a bad idea, too, if the expression becomes complex, that is, since this makes the code harder to read for anybody not familiar with it, which, after you have finished your project, is also applicable to you!
I hope my advice helps, and wish for you to gain so much intellect, that you never need to worry about optimization ever again - thanks for reading through my ‘rant’! "