Faster properties by veselink1 · Pull Request #60 · veselink1/refl-cpp (original) (raw)
This PR aims to fix the slow compilation uncovered in #58.
An optimisation is added to property-related utilities. The optimisation is based on the presumption that getters and setters are reflected (via the RELF_AUTO or REFL_FUNC macros) one after the other. The optimisation consists of checking the neighbouring members first, before resorting to a linear search.
Applies to:
REFL_AUTO( type(Point), func(get_x, property()), func(set_x, property()), func(get_y, property()), func(set_y, property()) )
But does NOT apply to:
REFL_AUTO( type(Point), func(get_x, property()), func(get_y, property()), func(set_x, property()), func(set_y, property()) )
I have added a bench/ tree, which will be used for benchmarks. Only one benchmark exists at the moment - bench-large-pod.cpp, which iterates over the members of a large POD with getters and setters and matches property getters to setters via get_reader/writer.
Results of compilation of bench-large-pod.cpp:
Without the optimisation:
Command being timed: "make large-pod"
User time (seconds): 41.69
System time (seconds): 1.01
Percent of CPU this job got: 99%
Maximum resident set size (kbytes): 3440424
With the optimisation:
Command being timed: "make large-pod"
User time (seconds): 10.38
System time (seconds): 0.42
Percent of CPU this job got: 99%
Maximum resident set size (kbytes): 1319484