I think I've just found a case when a premature optimisation isn't necessarily evil
-
@dkf said in I think I've just found a case when a premature optimisation isn't necessarily evil:
you're doing something insanely elaborate in C++ probably involving boost, or you've got a serious problem.
Yes.
-
@Bulb said in I think I've just found a case when a premature optimisation isn't necessarily evil:
Apparently the complexity of the code isn't worth the computational complexity benefits
We looked into this for the string type used in the core of Tcl's implementation (which is a very hot spot indeed, so anything done there is very carefully tested). The code required isn't just complicated, it's insane. We threw the idea out because it required making the code effectively unmaintainable. It also has almost no gains for almost all common use cases; most strings are actually mostly simple, and arrays are an unreasonably good data structure in the first place.
-
And quibbling over how to do string concat is exactly the kind of thing that the saying that premature optimization is evil is all about. In like 95% of cases, it won't make any measurable difference in anything, so write it the simplest and easiest to read way until you prove that it actually is a performance bottleneck.
-
@ufmace said in I think I've just found a case when a premature optimisation isn't necessarily evil:
write it the simplest and easiest to read way until you prove that it actually is a performance bottleneck
Pro-tip: If you're doing much string manipulation, look closely at whether concatenation is a bottleneck. It often actually is…
-
@dkf said in I think I've just found a case when a premature optimisation isn't necessarily evil:
@ufmace said in I think I've just found a case when a premature optimisation isn't necessarily evil:
write it the simplest and easiest to read way until you prove that it actually is a performance bottleneck
Pro-tip: If you're doing much string manipulation, look closely at whether concatenation is a bottleneck. It often actually is…
Pro-er-tip: If you don't have a good "bad string handling" radar, have your code reviewed by someone who does. For most seasoned developers, string concat code that's going to be a problem is visible from space.
-
@Jaime said in I think I've just found a case when a premature optimisation isn't necessarily evil:
For most seasoned developers
I wish I believed that, but I've seen too much code produced by supposed professionals where fixing the utterly obvious stuff solved their performance troubles that had been vexing them for ages…