orika-mapper / orika

Simpler, better and faster Java bean mapping framework
http://orika-mapper.github.io/orika-docs/
Apache License 2.0
1.29k stars 269 forks source link

Minimize same getter calls #346

Open porunov opened 4 years ago

porunov commented 4 years ago

During mapping we call getters multiple times. For different situations I see different amount of getter calls (2-5 calls for a single field). I case our getter has slow computation (for example, database calls, or generally complex logic) it may cause additional delays which could be omitted if we would call a getter only once. Other possible problem which could be is unnecessary or unpredicted computation (for example, if we change something between each call of the getter method). To mitigate this issue I would propose minimize getter calls (ideally we should call a getter only once, if it is needed). A possible solution, could be making a variables for each mapping field of source object and destination object (optionally). After that we could use created variables instead of calling getters to retrieve the value.