mardi 4 août 2015

Code design: performance vs maintainability

Contextualisation

Im am implementing a bytecode instrumenter using the soot framework in a testing context and I want to know which design is better.

I am building the TraceMethod object for every Method in a Class that I am instrumenting and I want to run this instrumenter on multiple Classes.

Which Option offers more performance(Space–time)?

Option 1: (Maps)

public class TraceMethod {
    boolean[] decisionNodeList;
    boolean[] targetList;
    Map<Integer,List<Integer>> dependenciesMap;
    Map<Integer,List<Double>> decisionNodeBranchDistance;
}

Option 2: (Objects)

public class TraceMethod {
    ArrayList<Target> targets = new ArrayList<Target>(); 
    ArrayList<DecisionNode> decisionNodes = new ArrayList<DecisionNode>();
}

public class DecisionNode {
    int id;
    Double branchDistance;
    boolean reached;
}

public class Target {
    int id;
    boolean reached;
    List<DecisionNode> dependencies;
}

I have implemented the option 2 by myself, but my boss suggest me the option 1 and he argue that is "lighter". I saw that in this article "Class Object vs Hashmap" that HashMaps use more memory than Objects, but im still not convinced that my solution(option 2) is better.

Its a simple detail but i want to be sure that I am using the optimal solution, my concern is about performance(Space–time). I know that the second option are way better in term of maintainability but i can sacrifice that if its not optimal.

Aucun commentaire:

Enregistrer un commentaire