|
|
|
|
|
by elweston2
2400 days ago
|
|
The way I usually follow it is
1) Is this OK? For example It is only called once in the code in an error path?
2) Did I do something silly? For example, I left in some extra debug code.
3) is the code doing something silly? For example extra work, dragging in extra data that is not needed?
4) is the code written in a way that causes extra work, re-init on inner loop, loop hoisting, etc
5) Is there a better algorithm for this? Binary search vs linear?
6) is the code doing too many things at once. De-serialize it re-serialize it
7) Is there a better abstraction for this? Monolith code vs microservice?
8) Is there any compiler switches that are 'easy' wins? Packing, -O2, etc? Usually not.
9) What sort of memory arch does this machine have? It varies between machines even for the x86 world. For example if I rearrange my memory structures do I use less cache and emit less code. The cache line on this box is x bytes and on that box is y bytes. Some languages do not lend themselves well to this one due to the way their VM/ISA is written.
10) is there some asm that would help? usually not. Usually 1-7 are all you need. If you get all the way to 10 you are in the deep end for most things. Big O is good for many things. But in reality big O is O(N)+C where the C can get you. That is where the later steps help. But usually you can totally ignore it. Most of the big wins I get are just from flipping out a bad search for a O(log(n)) search, or removing 'extra' code. |
|