Repository navigation
Description
It's time for us to have "the talk."
The talk about how using an interpreter to evaluate our functions at runtime isn't nearly as efficient as I thought it was! This project was made within the assumption that the performance loss from interpreting operators as a stack was not noticeable but, guess what? It is.
I noticed this yesterday when messing around with the textbox and tried to write the expression z^327 in the form of z*z*z*z... (as one does) and came across terrible performance
Yes, we expect bad performance for evaluating 327 multiplications regardless of whether it's interpreted or compiled, but how bad? To test this, i replaced this line in the fragment shader:
vec2 func_value = run_stack(operator_stack,constants_stack,z);with this
vec2 func_value = mult(z,mult(z,mult(z,mult(z,mult(z,mult(z,mult(z,mult(z,mult(z,mult(z,mult( [...]The results speak for themselves:
A compiler step would do just that. We could somewhat simply convert our reverse-polish notation back to infix, create a shader string, compile it and boom! Extra performance. Are we axing the interpreter, then? No way!
Compiling takes time, and the instant function preview we get right now is impossible with a compiler. What we are doing is using what we currently got as a preview. The user can then press a key to compile the function, giving them a "real deal" program that's far, far faster.
This compile step could also help us with the precision thing. I've been looking a lot on how to improve our shader precision, but almost all responses point to very performance-heavy solutions, that may be excusable if we have a compiled, faster way of doing things.
Here are the steps we'll have to take for this:
- Converting a
TokenOperatorinto it's corresponding GLSL function - Converting our
operator_stackinto an infix string - Creating a new
Shaderclass for dynamically recompiling shaders - Switching between shaders at runtime
- (Optional) Asynchronously waiting for the compiled shader to finish compiling before showing it


Activity
TokenOperatorinto it's corresponding GLSL function #24operator_stackinto an infix string #25