Horde3D

Next-Generation Graphics Engine
It is currently 01.11.2024, 00:56

All times are UTC + 1 hour




Post new topic Reply to topic  [ 37 posts ]  Go to page Previous  1, 2, 3  Next
Author Message
PostPosted: 26.08.2008, 18:15 
Offline

Joined: 04.04.2008, 16:28
Posts: 13
Quote:
There is also the matter of optimisations - high level languages are much simpler to optimise.


That's probably more of an opinion. The fact is Python runs in some kind of VM, and there is no amount of optimizations that will outperform a compiled piece of code.

Quote:
If you look at C/C++, they are designed to map fairly closely to the underlying assembly code.


I don't know if you have any experience with ASM, but take it from me C/C++ aren't anything close to "map fairly closely". Just because it the compilers emit ASM doesn't mean they are similar.

Quote:
This is good if you are hand optimising, but if you want to leave it up to the compiler, the compiler doesn't have much to work with. Python is modelled closely on concepts, rather than assembly, so the compiler/interpreter has an incredible amount of leeway to optimise. Then add in JIT, which lets the interpreter optimise specific sections of code on the fly, based on their usage patterns...


Again, you are assuming that the C++ is poorly coded compared to the Python code. Just because the Python interpreter can optimize, doesn't mean that a well written C/C++ routine is slower because it can't be optimized much further.

Quote:
I do the bulk of my coding directly in python - not because the resulting executable is faster than C++ (it often isn't), but because it cuts the amount of code I have to write by about 85%


I tried Python many times, but I just hate the concept of using indention to delimit blocks of code. I am however a huge fan of Lua, and scripting languages in general. Later.


Top
 Profile  
Reply with quote  
PostPosted: 26.08.2008, 19:59 
Offline
Engine Developer

Joined: 10.09.2006, 15:52
Posts: 1217
Please note, that in general LUA is clearly faster than Python, that's why it is used in AAA games like Crysis. I have a factor of 5 in the back of my head.

EDIT: Check this: http://www.timestretch.com/FractalBenchmark.html


Top
 Profile  
Reply with quote  
PostPosted: 26.08.2008, 20:11 
Offline

Joined: 26.03.2008, 02:58
Posts: 160
To reply to the original question: Why using LUA and Python scripts in game programming ?

Speed of development - no need to (re)compile. Both languages have easy to use and short syntax's, and are very good to develop task oriented systems, like AI agents and other sort of list oriented tasks, "rules" that tend to become very long C++ statements.

Another reason is reuse and manageability. Many studios have huge amounts of code written to do all sorts of tasks, and this code can be reused for multiple games, it is also much easier to simply swap a script than having to "digg" code, possibly breaking code or creating errors and warnings like "variable XYZ is never used".

Yet another reason, it's much easier to test and run LUA or python scripts in game editors, that run the game as a viewport DLL with pluggable behavior.

So bottom line: There are multiple advantages to using scripting languages for game development, and one big disadvantage, you do get a performance "run-time" penalty. How important that is, depends from project to project, and there are N possible solutions to boost your game performance.


Top
 Profile  
Reply with quote  
PostPosted: 26.08.2008, 20:14 
Offline

Joined: 15.06.2008, 11:21
Posts: 166
Location: Germany
http://shootout.alioth.debian.org/gp4/b ... &lang2=lua

http://shootout.alioth.debian.org/gp4/b ... ng2=luajit

Some nice language comparison.


Top
 Profile  
Reply with quote  
PostPosted: 27.08.2008, 03:56 
Offline

Joined: 21.08.2008, 11:44
Posts: 354
phoenix64 wrote:
http://shootout.alioth.debian.org/gp4/benchmark.php?test=all&lang=python&lang2=lua

http://shootout.alioth.debian.org/gp4/b ... ng2=luajit

Some nice language comparison.


Thanks a lot about benchmarking and showing differences clearly !
It was so much helpful !


Top
 Profile  
Reply with quote  
PostPosted: 27.08.2008, 04:23 
Offline

Joined: 08.11.2006, 03:10
Posts: 384
Location: Australia
I'm suprised to see that the JIT version of Lua actually beat C++ in one of the benchmarks on that site! (heavy floating point math)

The JIT version of python also beat C++ in one benchmark ;) (heavy threading)


Top
 Profile  
Reply with quote  
PostPosted: 27.08.2008, 13:24 
Offline

Joined: 04.04.2008, 16:28
Posts: 13
Quote:
I'm suprised to see that the JIT version of Lua actually beat C++ in one of the benchmarks on that site! (heavy floating point math)

The JIT version of python also beat C++ in one benchmark ;) (heavy threading)


Wow, that's impressive. Just imagine if you could somehow use LuaJIT the way we use regular Lua now.


Top
 Profile  
Reply with quote  
PostPosted: 27.08.2008, 15:35 
Offline

Joined: 22.11.2007, 17:05
Posts: 707
Location: Boston, MA
lzdude69 wrote:
Quote:
There is also the matter of optimisations - high level languages are much simpler to optimise.

That's probably more of an opinion. The fact is Python runs in some kind of VM, and there is no amount of optimizations that will outperform a compiled piece of code.
That higher level languages allow more scope for optimisation is a *fact*, well established in compiler theory.

Quote:
Quote:
If you look at C/C++, they are designed to map fairly closely to the underlying assembly code.

I don't know if you have any experience with ASM, but take it from me C/C++ aren't anything close to "map fairly closely". Just because it the compilers emit ASM doesn't mean they are similar.
I have been directly involved with compiler implementation, and have a lot of ASM experience (on x86, ARM and SPARC) - Believe me when I say that C very closely maps the underlying assembly. The syntax doesn't resemble ASM, but the structure does, loops are just conditionals tied to jumps, pointers are an ASM concept, all the types are matched to machine types, etc.

Quote:
Quote:
This is good if you are hand optimising, but if you want to leave it up to the compiler, the compiler doesn't have much to work with. Python is modelled closely on concepts, rather than assembly, so the compiler/interpreter has an incredible amount of leeway to optimise. Then add in JIT, which lets the interpreter optimise specific sections of code on the fly, based on their usage patterns...
Again, you are assuming that the C++ is poorly coded compared to the Python code. Just because the Python interpreter can optimize, doesn't mean that a well written C/C++ routine is slower because it can't be optimized much further.
I am not saying that you can't tweak the C++ algorithm to perform better, I am saying that a naively written algorithm in python will be as fast or faster than a naively written algorithm in C++. Sure, by writing for the compiler you can get optimal ASM output, but a lot of programmers don't have the knowledge of compilers and ASM to do that.

Quote:
Quote:
I do the bulk of my coding directly in python - not because the resulting executable is faster than C++ (it often isn't), but because it cuts the amount of code I have to write by about 85%
I tried Python many times, but I just hate the concept of using indention to delimit blocks of code. I am however a huge fan of Lua, and scripting languages in general. Later.
Meaningful whitespace is one of my main gripes with python, but it does at least guarantee that everyone uses a consistent code format ;)

_________________
Tristam MacDonald - [swiftcoding]


Top
 Profile  
Reply with quote  
PostPosted: 27.08.2008, 17:43 
Offline

Joined: 04.04.2008, 16:28
Posts: 13
Quote:
That higher level languages allow more scope for optimisation is a *fact*, well established in compiler theory.


I have been using a largely unknown, but great programming language for years now called Xblite(works with Horde3D great). It's BASIC syntax, and IMHO BASIC is far "higher" than Python when it some to "level":P It directly emits ASM (just like a C/C++ compiler), but does that make it possible for better optimization...not really. I personally would say C/C++ is a fairly high level language, and so is Python, Python just comes with a plethora of crap that you would otherwise have to implement yourself.

Quote:
I have been directly involved with compiler implementation, and have a lot of ASM experience (on x86, ARM and SPARC) - Believe me when I say that C very closely maps the underlying assembly. The syntax doesn't resemble ASM, but the structure does, loops are just conditionals tied to jumps, pointers are an ASM concept, all the types are matched to machine types, etc.


Well, you can say that about any compiled language. Code that runs on a VM is a little different obviously, but sure enough the VM had to come from somewhere. I was referring solely to syntax, as everything has to eventually resemble ASM. Does Python loops/conditionals not resemble C/C++/ASM/BASIC loops? Are Python types completely alien, or do the mimic types we've been using for ever?

Quote:
I am not saying that you can't tweak the C++ algorithm to perform better, I am saying that a naively written algorithm in python will be as fast or faster than a naively written algorithm in C++. Sure, by writing for the compiler you can get optimal ASM output, but a lot of programmers don't have the knowledge of compilers and ASM to do that.


Fair enough. But I disagree that you need a decent knowledge of ASM or the compiler to write concise/efficient code in anything other than an interpreted language like Python. To even write an algorithm faster/better than C++, wouldn't that require a very similar knowledge of the Python VM?

Quote:
Meaningful whitespace is one of my main gripes with python, but it does at least guarantee that everyone uses a consistent code format ;)


That was the whole reason for that right?


Top
 Profile  
Reply with quote  
PostPosted: 27.08.2008, 18:23 
Offline

Joined: 22.11.2007, 17:05
Posts: 707
Location: Boston, MA
lzdude69 wrote:
Quote:
That higher level languages allow more scope for optimisation is a *fact*, well established in compiler theory.
I personally would say C/C++ is a fairly high level language, and so is Python, Python just comes with a plethora of crap that you would otherwise have to implement yourself.
Nope. C is as close as you get to the metal without going to ASM (and C++ not much better). Python has garbage collection, doesn't have pointers, doesn't have declarations, doesn't use machine types... the list goes on. That the syntax resembles C++ is neither here nor there.

Quote:
Well, you can say that about any compiled language. Code that runs on a VM is a little different obviously, but sure enough the VM had to come from somewhere. I was referring solely to syntax, as everything has to eventually resemble ASM. Does Python loops/conditionals not resemble C/C++/ASM/BASIC loops? Are Python types completely alien, or do the mimic types we've been using for ever?
Compare these snippets, the first in python and the second in C++:
Code:
[x*x for x in v if x > 3]

Code:
template <typename T>
std::vector<T> func(const std::vector<T> &v) {
   std::vector<T> r;
   for (int i = 0; i < v.size(); i++)
      if (v[i] > 3)
         r.push_back(v[i]*v[i]);
   return r;
}
They both perform exactly the same operation (return a list of the squares of all items greater than 3 in a source list). However, even with the template, the C++ version still only works on one type of container, while the python version will work on any container (list, array, file, etc.). The C++ version is also 8 lines instead of 1, and is harder to read and maintain. But the big issue here, and the main win for Python, is that the python version can be automatically and transparently parallelised across multiple threads by the VM, and the C++ version cannot.

Quote:
To even write an algorithm faster/better than C++, wouldn't that require a very similar knowledge of the Python VM?
Nope, see the above example. High level languages express 'concepts', low-level languages express 'operations'. Operations can never be handled as well by the compiler as concepts.

This is the reason why Google wrote their backend in Python, Yahoo wrote theirs in LISP, Apple uses Objective-C for all their stuff, etc. You can't really write stuff like Google's distributed map-reduce search algorithm in a low-level language like C++. And even if you do, the performance wont be any better, and the maintainability will suck.

Quote:
Quote:
Meaningful whitespace is one of my main gripes with python, but it does at least guarantee that everyone uses a consistent code format ;)
That was the whole reason for that right?
Quite likely.

_________________
Tristam MacDonald - [swiftcoding]


Top
 Profile  
Reply with quote  
PostPosted: 01.09.2008, 07:30 
Offline

Joined: 08.11.2006, 03:10
Posts: 384
Location: Australia
I just came across two new native-compilation systems for Lua and Python:
http://code.google.com/p/llvm-lua/
http://code.google.com/p/py2llvm/


Top
 Profile  
Reply with quote  
PostPosted: 01.09.2008, 08:35 
Offline

Joined: 21.08.2008, 11:44
Posts: 354
DarkAngel wrote:
I just came across two new native-compilation systems for Lua and Python:
http://code.google.com/p/llvm-lua/
http://code.google.com/p/py2llvm/


Is it possible to add some tutorials about binding Lua, JIT versions and "HOW TO INTEGRATE THEM" to the game on the wiki :?:


Top
 Profile  
Reply with quote  
PostPosted: 01.09.2008, 10:45 
Offline
Tool Developer

Joined: 13.11.2007, 11:07
Posts: 1150
Location: Germany
Lua Bindings for C functions are easy to create. You can check the Horde Lua Bindings in the editor if you want to know how to create them.


Top
 Profile  
Reply with quote  
PostPosted: 02.09.2008, 06:45 
Offline

Joined: 21.08.2008, 11:44
Posts: 354
Volker wrote:
Lua Bindings for C functions are easy to create. You can check the Horde Lua Bindings in the editor if you want to know how to create them.


PLEASE ADD SOME TUTORIALS ABOUT COMPILING LUA AND ... WITH MINGW


Top
 Profile  
Reply with quote  
PostPosted: 02.09.2008, 06:57 
Offline

Joined: 08.11.2006, 03:10
Posts: 384
Location: Australia
Siavash wrote:
PLEASE ADD SOME TUTORIALS ABOUT COMPILING LUA AND ... WITH MINGW
I don't think you understand how this whole "open source" thing works... Most of us have full-time jobs - Volker's contributions to the Horde project are entirely voluntary, so yelling at him with demands for help with things that are, frankly, not even related to horde is rather rude.

Have you read this page: http://lua-users.org/wiki/BuildingLua?


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 37 posts ]  Go to page Previous  1, 2, 3  Next

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 17 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group