Skip to main content
gamedev.net
🔒 Locked

Python call overhead - execute list optimization idea

Started by adal Dec 30, 2006 at 6:10 AM 0 replies 750+ views
Original Post
adal
adal
Hi. I'm currently implementing a small OpenGL 3D engine in Python. Since I have a small mesh based mostly static world, I think that it will be fast enough after some optimizations. At this stage I'm getting 20-30 fps on a 200k triangle scene in 1280x1024 with 9 per pixel spot-lights on an ATI x1300 Pro/Athlon XP 3000+ which is more than I expected given the video card. The app is very CPU bound since the frame-rate remains the same when using a small window and it goes to 50-60 fps on an Intel Core 2 Duo E6600 with same video-card (recent modifications brought it down to 5 fps because of the very inneficient light position uniform updating code). I already got a huge speed increase by moving the matrix multiplication code from Python to C++. Now I am thinking of doing this: instead of walking the scene graph each frame and rendering each node from Python I will do this only once in the beginning and build for each object a table which will describe the OpenGL calls required to draw the object. Something like this: 1, glActiveTexture, 0 2, glBindTexture, GL_TEXTURE_2D, texture 1, glUseProgram, program 4, glUniformMatrix4fv, wvpLocation, 1, GL_FALSE, wvpMatrix 1, glEnableVertexAttribArray, 0 6, glVertexAttribPointer, 0, 3, GL_FLOAT, GL_FALSE, 0, NULL The first number is the function parameter count, followed by the actual pointer to the OpenGL function followed by 32 bit parameters. Then I invoke a C++ method which walks the table and executes it. The only problem is computing stuff that varies from frame to frame, like wvpMatrix. I see two possibilities: either adding a special marker to the table which would make the C++ code call back into Python to do the computation or computing these values in a preprocessing step in Python code and storing the results in a temporary structure for them to be available when executing the table. What I want to ask is this: does this kind of optimization has a name? Any papers on it? What are your thoughts?
Kylotan
Kylotan
Executing functions in one language based on instructions in another is called scripting. ;) I don't think there's anything specific here that qualifies as a special optimisation. All you're doing is pushing more work back up to C++, which is reasonable and very common.

You say it's CPU bound, but do you know which functions use that CPU time? Doing all this may just be a waste of time if the CPU usage is mainly in the OpenGL library calls, for example. In my opinion you should profile before making any significant changes.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.