Performance anti patterns

前端 未结 18 911
天涯浪人
天涯浪人 2021-02-05 19:29

I am currently working for a client who are petrified of changing lousy un-testable and un-maintainable code because of \"performance reasons\". It is clear t

相关标签:
18条回答
  • 2021-02-05 19:59

    Julian Birch once told me:

    "Yes but how many years of running the application does it actually take to make up for the time spent by developers doing it?"

    He was referring to the cumulative amount of time saved during each transaction by an optimisation that would take a given amount of time to implement.

    Wise words from the old sage... I often think of this advice when considering doing a funky optimisation. You can extend the same notion a little further by considering how much developer time is being spent dealing with the code in its present state versus how much time is saved by the users. You could even weight the time by hourly rate of the developer versus the user if you wanted.

    Of course, sometimes its impossible to measure, for example, if an e-commerce application takes 1 second longer to respond you will loose some small % money from users getting bored during that 1 second. To make up that one second you need to implement and maintain optimised code. The optimisation impacts gross profit positively, and net profit negatively, so its much harder to balance. You could try - with good stats.

    0 讨论(0)
  • 2021-02-05 20:00

    One that I've run into was throwing hardware at seriously broken code, in an attempt to make it fast enough, sort of the converse of Jeff Atwood's article mentioned in Rulas' comment. I'm not talking about the difference between speeding up a sort that uses a basic, correct algorithm by running it on faster hardware vs. using an optimized algorithm. I'm talking about using a not obviously correct home brewed O(n^3) algorithm when a O(n log n) algorithm is in the standard library. There's also things like hand coding routines because the programmer doesn't know what's in the standard library. That one's very frustrating.

    0 讨论(0)
  • 2021-02-05 20:00

    Exploiting your programming language. Things like using exception handling instead of if/else just because in PLSnakish 1.4 it's faster. Guess what? Chances are it's not faster at all and that two years from now someone maintaining your code will get really angry with you because you obfuscated the code and made it run much slower, because in PLSnakish 1.8 the language maintainers fixed the problem and now if/else is 10 times faster than using exception handling tricks. Work with your programming language and framework!

    0 讨论(0)
  • 2021-02-05 20:00

    Appending to an array using (for example) push_back() in C++ STL, ~= in D, etc. when you know how big the array is supposed to be ahead of time and can pre-allocate it.

    0 讨论(0)
  • 2021-02-05 20:02

    Do not refactor or optimize while writing your code. It is extremely important not to try to optimize your code before you finish it.

    0 讨论(0)
  • Variable re-use.

    I used to do this all the time figuring I was saving a few cycles on the declaration and lowering memory footprint. These savings were of minuscule value compared with how unruly it made the code to debug, especially if I ended up moving a code block around and the assumptions about starting values changed.

    0 讨论(0)
提交回复
热议问题