3 ms·
Step one is just clone() everywhere all the time. Then you should cut back AFTER analyzing where all of your memory is being lost to.
by teaearlgraycold 4y ago
Step one is just clone() everywhere all the time. Then you should cut back AFTER analyzing where all of your memory is being lost to.
- chombier 4y agoCan one really escape clone hell afterwards, though?
- wongarsu 4y agoI generally go by the principle to borrow if I can without effort, otherwise I think a second of the code is in the critical path or the object is megabytes in size. If neither is the case, I clone without shame. The remaining 0.1% gets my attention (Arc, lifetime annotations, refactoring, or whatever is appropriate). The important part is perspective. Nobody cares if you clone your command line arguments ten times during startup. As Dijkstra said, optimize the 2% of your program that matter, keep the rest simple
- kaba0 4y agoExactly. Even very experienced people will be easily misled to believe something is performance-sensitive -- computers are ridiculously fast. Like honestly, if it is not a tight loop chances are it seriously doesn't matter what you do. Remember, we write plenty of shell scripts that literally spawn a new process for almost every line, and yet they feel instantaneous.