Comments (9)
Yeah, refl-cpp doesn't handle large classes very well. Splitting up classes in this way might not be possible due to language limitations. There might be better ways to work around this issue.
Just to clarify, are you saying you have multiple classes with ~200 reflected members (getters and setters included)? And you do some sort of looping over of the members, matching getters and setters, and this is what is causing long compile times? Are you using the get_reader/get_writer API?
from refl-cpp.
I have several large classes, many around 100 members, but a couple are around 200 members. I loop using the get_reader/get_writer api. You've helped me out before by speeding it up considerably a few months ago.
The chunk idea is motivated by the notion that I could separate the getters and setters into chunks so that get_reader/get_writer would not have to search so many members. (I'm hoping this rewrite could be limited to only the largest classes, to avoid having to refactor the entire reflection code base.)
from refl-cpp.
Another approach might be to have a way to specify the setter in the macros.
from refl-cpp.
Can you try this PR #72 and see if it improves compile times for your use case? Thanks.
from refl-cpp.
It may make a slight difference, but it isn't a lot. I just had a different idea of something to try: I could sort the member of the largest classes and then add attributes to all their getters that basically tell them to use n+1 for their setters. Then I could avoid has_writer/has_reader entirely.
Since we last corresponded (several months ago) I have created a script to generate the REFL_FUNC code automatically from the existing Lua environment. Sorting a few of the existing larger classes will not be an issue. (The script can also add attributes, because it's writing a text file with anything I tell it to.)
But I'm thinking this would be less messy code if activated by a type-level attribute. If such a thing exists now, I haven't found it in the docs. (But I easily might not have.) Still, a user-defined class-level attribute would be a cool nice to have. I mean the ability to add an attribute like this:
REFL_TYPE (mytype, fancy_attribute())
I could accomplish the same goal by adding a template bool parameter to my looping routine, but that seems less elegant than a user-defined attribute on REFL_FUNC
.
from refl-cpp.
On further reflection, maybe a setter_is_next
attribute on the getter is all I need. Going to try it.
from refl-cpp.
Hmm. Except in the loop:
for_each(members, [&](auto member)
{
// I have member.
// how do I get the next member from it?
});
from refl-cpp.
I could sort the member of the largest classes and then add attributes to all their getters that basically tell them to use n+1 for their setters. [...]
On further reflection, maybe a setter_is_next attribute on the getter is all I need. Going to try it.
This is an optimisation that is already done internally and does make a big difference in my experience. The PR I linked further improves performance.
Each setter must be either right before or right after the corresponding getter, there is no need to specify additional attributes. Definitely worth trying.
Line 3600 in 7c9154d
Just to give an idea of the difference that it makes, Matching getters and setters of a class with 400 methods (200 properties) takes 4s to compile if the properties as sorted and #72 is applied. Pre #72 and in the case of unsorted getters and setters, compilation takes 25s.
https://github.com/veselink1/refl-cpp/blob/master/bench/bench-large-pod-search.cpp
from refl-cpp.
For context, my Windows machine is severely under-powered. (This is a problem in itself, but since my main dev machine is my Mac, which is lightening-fast, I have been living with it.) All of the following timings are from the under-powered Win machine.
Original compile time for largest class (which is in its own cpp): ~7:00.
This is to confirm that:
- sorting so that setters follow getters reduces the compile time to ~2:00.
- applying #72 further reduces the time to ~40s.
- directly using
member_index + 1
as the setter reduces the compile time to less than 30s. (I gleaned how to do that fromget_writer
.)
I'm guessing the difference between the last two bullets is primarily because get_writer
tries member_index-1
first. If I may be so bold as to suggest, because "Get" comes alphabetically before "Set", I would try member_index+1
first for get_writer
and member_index-1
first for get_reader
.
Also, the comments are incorrect, fwiw.
from refl-cpp.
Related Issues (20)
- GetDateFormat getter vs. the Win32 API HOT 2
- Use of `get_reader` and `has_writer` produces absurdly long compile times HOT 18
- Q: make REFL_AUTO, REFL_TYPE etc. callable from nested namespace HOT 7
- Port to vcpkg HOT 3
- Fix warnings for strict variadic macro checks (stronger C++20 enforcement)
- refl::util::detail::filter(..) inverts order of member list HOT 2
- Is there a way to reflect private fields? HOT 5
- Q: how to reflect on member functions' parameters and return types? HOT 5
- Is there a possibility of adding features like Boost.PFR? HOT 3
- How to implement my case with this library? HOT 1
- Question. a generic getter function for reflected type HOT 1
- Enum reflection HOT 2
- Access member descriptor from pointer-to-member HOT 4
- Field offsetof HOT 4
- Member list empty when using reflect<T>(), but works fine with reflect(const T&) HOT 1
- How to resolve the non-const signature of a class method. HOT 2
- Q: Implementing a member attribute for "Default value" to use in ctors
- (unknown)**ย that is all i get for typename HOT 1
- Deleted HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from refl-cpp.