Do I always have to think about performance?

后端 未结 21 717
小蘑菇
小蘑菇 2021-02-04 04:16

I come from a DBA world and performance has always been an obsession. I am turning to development and I always think about performance, constantly, all the time.

Reading

21条回答
  •  误落风尘
    2021-02-04 04:34

    Nope, if you're going to be thinking of something then think about delivering value to your employer/client and customers. Think about what counts for them.

    That said, performance is important but it can lead to ruin.

    Dawn of War 2 was released in February with a game breaking bug that destroys multi-player. The issue? Population cap. When a squad is re-enforced the last unit takes up double the cap due to a coding error. This means you can be in a situation where you have a very small army and when you try to create a new unit the game tells you that you have too many units on the field. Most frustrating.

    Why should this be an issue? How can this be an issue that only occurs with re-enforcement? If it was an issue with just buying the unit then surely it would have been discovered in testing!

    Well my guess is that it is due to premature optimisation. The developer didn't want to foreach all the units when you click the "buy unit" button and instead made pop-cap like a bank so when a unit is created it takes cap out of the bank and when it dies pop cap is put back into the bank. Sure that's more performant, but one little mistake throws the whole bank out of step.

    So what's worse, a small perf hit when you press that "buy unit" button or a lot of flaming in the Dow2 forum, angry customers and MS dragging their heels with certifying the fix meaning that it isn't fixed yet?

    In a lot of cases its better off marking a

    // todo: performance could be better
    // try doing xyz if we need to improve it
    

    because the performant version takes more time and adds a maintenance cost to the code.

    The performance you should be worrying about is delivering a solution to your client that is satisfactory and fulfills their need. The speed of getting to the release date is usually more important.

    There are scenarios where general performance is important such as embedded systems but this should be known as a restriction up front and is a special context you should be aware of before you hit the code.

提交回复
热议问题