0

Background:
I am working on a C++ code-base with around 10 files each having 100+ lines of code. There is a data class that is fundamental to my project and is used in other classes/functions throughout my pipeline.

Initially, the class had 3-4 members based on types of information that I needed. Then I decided to use a map so that there is no limit on the types of information and more can be added easily (from the code itself, potentially based on input) if needed later. However, the map increased the run-time by atleast 3-4 times.

So temporarily I want to revert back to manually adding class members in the code. This will need 30-40 changes in the codebase from object.info["typeofinfo"] as in a map (.info is the map member here) to object.typeofinfo as in manually defined class members. Doing this once is not a problem, but in the future I might want to try my luck at dynamic members (using the map) again.

Questions:
a) Is there a quick way to switch between these 2 versions at random points in the development of my project (which will only grow in size).
b) Is there a faster way (than map/unordered_map) to make the number of members in a class dynamic so that I can add more types of information into the class from within the code-base based on the input

  • 1
    Use version control to run two separate branches. – Carlos Jul 19 '20 at 10:32
  • Have you tried indexing your map by an enum rather than a string? My expectation here would be that it is the string comparison that is causing most of your slowdown. – alcedine Jul 19 '20 at 10:59
  • I'm a bit skeptical about the effectiveness of branching for this as I might modify these lines later and simple merging would cause issues. I think an enum map will make it faster, but not fast enough because this data class is a sub-class inside a lot of other classes which get passed around throughout my pipeline. If it helps, I'm dealing with a graph, and the node Class of each graph has this data class as a sub-class (so performance tanks) – Shashwat Goel Jul 19 '20 at 12:17

0 Answers0