Skip to content

Use of get_reader and has_writer produces absurdly long compile times #58

@rpatters1

Description

@rpatters1

I use refl-hpp to import C++ classes into LuaBridge. A requirement of LuaBridge is that to import a writable property you must import its getter and setter at the same time. I have hacked around this with modifications to LuaBridge that allow me to import the setters separately, but these hacks are not safe in the long term and will not be merged back into the LuaBridge repository.

An alternative is to use get_reader and has_writer to import the properties correctly. These work, but they increase the compile-time cpu and memory requirements by a factor of 10x or more. What I've noticed in general with refl-cpp is that these requirements seem to increase exponentially with the number of members in the REFL_TYPE.

My code looks something like this:

template<class T>
void ProcessClass()
{
   constexpr auto type = refl::reflect<T>();
   constexpr auto members = get_members(type);

   for_each(members, [&](auto member)
   {
      if constexpr (refl::descriptor::is_property(member))
      {
         if constexpr (refl::descriptor::is_writable(member))
         {
            auto reader = refl::descriptor::get_reader(member);
            // etc.
         }
         else if constexpr (! refl::descriptor::has_writer(member))
         {
            // etc.
         }
      }
   });
}

I am wondering if you have a suggestion as to how to refactor this code to be more efficient at compile time. Is there some kind of hash table like std::map that runs at compile time? I have searched but couldn't find one. It would be nice if get_writer and get_reader could do a hash lookup on the display name rather than using find_one. I could pre-process the members in a separate loop if need be, but I haven't been able to figure out how.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions