Do I always have to think about performance?

后端 未结 21 723
小蘑菇
小蘑菇 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:40

    Answer 1:

    Many people rightly say "Don't think about performance, optimize later", but remember that they have unit tests. They can rewrite large portions of their codebase without fear of introducing bugs. If you rewrite without any unit tests, you have to manually test everything again, and this time around it's harder because the algorithms are more complex.

    You can put off optimization until later but you have to make sure you're prepared for it. If you don't have a workable plan for optimizing later (unit tests, tools to profile your code), then you'd best think about performance now because it will hurt you much more later on.

    Answer 2:

    Sometimes the simple working solution you first come up with runs in O(n^n) time. If you know you'll have large data sets, then go ahead and optimize it now.

    Answer 3:

    Some time ago, I got sick of the blemishes in PHP and tried to fix some of them. I wrote a framework which involved a base class that everything had to inherit from. It used method and property overloading, reflection, and just about every other advanced feature to make it work. Then I went ahead and used it in a massive project, using my own framework features instead of the basic language features like isset() and static. The project's code was a little more tidy, but the magic slowed down every method call, and property access by about 50x.

    If you're going to try and extend the language itself, you need to think about performance now because you have to re-write everything if you can't optimize it. C has a zero-cost macro system, go for your life. Javascript has no such system, be very careful about writing a new object inheritance system that you want to use everywhere.

提交回复
热议问题