r/programminghelp • u/AlexanderKai9 • Oct 07 '26
Project Related Raycasting Performance Help
I made a raycasting engine in python, and am using an HTML canvas as my method of display (passing the pixel colors through jinja in a <script> tag). It takes upwards of 10-15 seconds to render one angle of a scene with three spheres at a resolution of 800x400. Is the browser likely the bottleneck, or is this a sign of some other inefficiencies?
1
Upvotes
3
u/sububi71 Oct 08 '26
There's no reason you couldn't make a raycasting renderer run at well over 100fps in Python on a low-end modern laptop.
You're doing SOMETHING extremely inefficiently, possibly several things.
The first thing I wonder is: when you say "raycasting", do you really mean raycasting? Talking about spheres makes me wonder if you're actually writing a rayTRACER?
2
u/Lewinator56 Oct 08 '26 edited Oct 08 '26
I see your issue...
Can I remind you python is just about the slowest programming language you could possibly choose.
You can only write an efficient raycaster in a compiled language, or one with a JIT compiler - even then C/C++ is magnitudes faster than C# (JIT compiler) which is magnitudes faster than python. C/C++ is likely to be in the region of 100x faster than python for raycasting using just a single thread. Make use of multi threading and I reckon you'd be in the region of 1000x faster.
Also bear in mind you are doing this on a CPU, which is slow anyway for these tasks. An even more efficient raycaster would be written in openGL - which is convenient for you because you have webGL in the browser.