lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

It was thus said that the Great JeanHeyd Meneide once stated:
>     There is a significant speedup if you replace __index with a table
> instead of a function. If you look at this link here (
> ), there are some basic
> benchmarks of various frameworks and their call times for their
> implementations of C++ Member Functions ( I am the "sol2" cluster / row in
> the data ). You'll notice that we run fairly slow in terms of C++ member
> function call speed when compared to the fastest framework there. This
> puzzled me, as the process you describe for the function seemed like the
> only way to do it, so I looked into how other frameworks did it. After
> studying, I made a few changes and re-ran the benchmarks with the 2
> different styles of __index for accessing member functions when you do
> `myfoo:blah()`: ( the associated commit for
> the 'sol2 - table __index' row you see there is here[1] ).

  I have to wonder what you are doing that makes the C++ calls more
expensive than C calls.  From what I can see, if you want speed, avoid C++. 
I know that probably isn't an option but when call a C function is four
times faster than calling a C++ member function, something is wrong (unless
my understanding of C++ is in error and indeed, it is not as fast as C).

>      The process you described above is the old method we used (the bottom
> half of that CSV of data) and it is markedly slower. I do not know why it
> is markedly slower. But it is, and it's observable, and that's where my
> original question came from.

  If you don't know why it's slower, then perhaps an investigation is in

> > "Could you please specify a sample of what you mean by this?  I just want
> > to make sure I understand what you are asking."
>     A theoretical way for me to solve my problem would be to have the
> __index metamethod be a function (and incur the function call overhead),
> but to also somehow set fields on the userdata. E.g.,

  No no no, not how you would like to solve it, what are you trying to
accomplish?  Is it to take a C class:

	class Person
	  std::string name;
	  int age;
	  bool hired;
	  Person(std::string name, int age) : name(name), age(age), hired(false) {}
	  void hire() { hired = true; }
	  void fire() { hired = false; }
	  bool isHired() const { return hired; }
	  int getAge() const { return age; }
	  std::string getName() const { return name; }

and have Lua code automatically generated so one can call the various public
methods from Lua?  Not to automate this but make it easy to create functions
to do so?  Given the above, what would the Lua code look like?  The C++