satoren / kaguya

C++ binding to Lua
Boost Software License 1.0
345 stars 70 forks source link

Call member function is slow than property. #32

Closed aster2013 closed 8 years ago

aster2013 commented 8 years ago

Call member function is slow than property.

with sprite:GetPosition, sprite:SetPosition get fps 54 with sprite.position get fps 125

satoren commented 8 years ago

I’m sorry. Can you define KAGUYA_RETURN_VALUE_OPTIMIZATION 0 or change in kaguya/config.hpp ? If faster change. i remove it.

aster2013 commented 8 years ago

define KAGUYA_RETURN_VALUE_OPTIMIZATION 0 will faster than 1.

but the function call remain slow than property call.

satoren commented 8 years ago

OK. When I get home,will check it.

aster2013 commented 8 years ago

Bug. This function not push v to Lua.

namespace nativefunction
    {
#if KAGUYA_RETURN_VALUE_OPTIMIZATION
        template<typename T>
        struct is_return_reference_optimize :traits::integral_constant<bool,
            is_usertype<typename traits::decay<T>::type>::value &&
            (traits::is_pointer<T>::value   ||
            traits::is_lvalue_reference<T>::value)>{};

        template<typename T>
        inline int optimized_push_return_value(lua_State* state,T* v)
        {
            int top = lua_gettop(state);
            for (int i = 1; i <= top; ++i)
            {
                if (lua_type_traits<T*>::get(state, i))
                {
                    lua_pushvalue(state, i);
                    return 1;
                }
            }
            return util::push_args(state, v);
        };
satoren commented 8 years ago

Not bug (but very slow). If argument and return value(v) is same, push stack valuelua_pushvalue(state, i); , It is no newuserdata(not heap allocation).

aster2013 commented 8 years ago

I known what your mean. but only check argument type not argument value. eg.

Node* Node::CreateChild(const char* name);

will not push the return value to stack.

satoren commented 8 years ago

Omg! you are right. Thanks!

satoren commented 8 years ago

Forgot ==v , but already remove that.

aster2013 commented 8 years ago

Thanks. By the way, Where are you?

satoren commented 8 years ago

at home now.

satoren commented 8 years ago

No. it's seacret.

aster2013 commented 8 years ago

Sorry. Kaguya is cool. If you have time, I want to invite you work on Urho3D.

satoren commented 8 years ago

Thanks.