Questions tagged [micro-optimization]

Micro-optimization is the process of meticulous tuning of small sections of code in order to address a perceived deficiency in some aspect of its operation (excessive memory usage, poor performance, etc).

Micro-optimization is the process of meticulous tuning of small sections of code in order to address a perceived deficiency in some aspect of its operation (excessive memory usage, poor performance, etc).

Micro-optimization (and optimization in general) tends to be interesting to programmers because they enjoy finding clever solutions to problems. However, micro-optimization carries the connotation of a disproportionate amount of effort being expended to extract relatively small improvements.

That's not to say that micro-optimization is bad practice in all circumstances. Sometimes a small improvement in a part of a code base that gets used frequently (such as the innermost part of a loop) can yield big overall gains in system performance, and building code for highly constrained systems such as microcontrollers will often require cleverness to eke out the most performance from such a small system.

However, it can be tempting to indulge in the practice where it's not necessary, resulting in a lot of time being spent that could have been used more productively, and in code that is difficult to follow as "clever" solutions to problems are often more difficult to understand than simple solutions, and therefore a micro-optimization can have a negative impact on the maintainability of a piece of code.

Programmers are advised to avoid micro-optimization, unless they can make a solid justification for the problems outlined above being worth the performance gains. Should profiling of the code in question identify a hot-spot that is causing a performance bottleneck, then this can be sufficient justification for a micro-optimization.

900 questions
0
votes
0 answers

Understanding partial-register slowdowns from mov instead of movzx instruction

I'm very new to assembly language and trying to understand some of its working principles. I read this answer and have a question about the following wording: it avoids performance penalties that may result from writing to only the low 8 (or 16)…
St.Antario
  • 26,175
  • 41
  • 130
  • 318
0
votes
1 answer

Most optimized way to create associative array

What is the best (fastest, most readable, etc.) way to create associative array? Last time I saw that my co-worker, create small assoc array by: $array['is_enabled'] = false; In code review i pass my opinion that more readable form is: $array = [ …
0
votes
2 answers

optimizing match formula looping in vba

Lastrow = ActiveSheet.UsedRange.SpecialCells(xlCellTypeLastCell).Row For i = 3 To Lastrow Sheets("sample").Range("AM1000000").End(xlUp).Offset(1, 0).Select Selection.FormulaArray = _ "=IF(ISNUMBER(MATCH(1," & Chr(10) & " …
terny
  • 21
  • 2
  • 10
0
votes
1 answer

Are if-then-else statements slower in TI-Basic?

When coding on a very slow machine, such as a TI-89, every statement counts. I am often indecisive between two ways of writing if statements: If bool Then int = 0 Else int = 1 End or int = 1 If bool Then int = 0 End (Yes, I know with…
0
votes
1 answer

c# Denormalized Floating Point: is "zero literal 0.0f" slow?

I just read about Denormalized floating point numbers, should i replace all zero literals with almost-zero literal to get better performance. I am afraid that the evil zero constants in my could pollute my performance. Example: Program 1: float a =…
user2186597
  • 297
  • 2
  • 10
0
votes
3 answers

Storing document and window references in an object to get better performance

I have one question and don't know do I do right thing. I define window and document in objects or global variable in my pluins like this: var myplugin = { document : document || {}, window : window || {} }; After I call that when I need…
Ivijan Stefan Stipić
  • 6,249
  • 6
  • 45
  • 78
0
votes
1 answer

Optimizing upload: request sent

I'm working on an async uploader in JavaScript intended to send multi-gigabyte files to our server efficiently. It uses JavaScript's FileReader to slice the files 5MB chunks at a time, and send 5 chunks concurrently. Seems that the bottle neck is…
rodrigo-silveira
  • 12,607
  • 11
  • 69
  • 123
0
votes
1 answer

x86 - Instruction-level parallelism - optimal order of instructions

Which of the following two snippets of x86_64 code should be fastest? Or no difference at all? ; #1 bsf rax, rdi mov rdx, -1 cmove rax, rdx vs. ; #2 mov rdx, -1 bsf rax, rdi cmove rax, rdx (Or an alternative…
Cecil Ward
  • 597
  • 2
  • 13
0
votes
1 answer

How to maximize performance of an asynchronous scheduler?

I've noticed a strange technique in JavaScript that I've used to increase performance in repetitive processes that paint on a canvas. In the future, I plan to use a SharedBufffer or even a SharedCanvas when they become implemented, but in the…
0
votes
1 answer

What is the minimal number of dependency chains to maximize the execution throughput?

Given a chain of instructions linked by true dependencies and repeated periodically (i.e. a loop), for example (a->b->c)->(a->b->c)->... Assuming that it can be split into several shorter and independent sub-dependency chains to benefit from…
0
votes
2 answers

C++ - Are const parameters and class variables pessimization?

I'm trying to figure out when const should be used when writing C++ code. Are these all examples of pessimization or is it beneficial to write code this way?: Example 1: int findVal(const int OTHER_VAL) const { switch(OTHER_VAL) { case…
0
votes
1 answer

x86 decoding of multi-uop instructions

Agner Fog in his microarch.pdf says: Decoding becomes more efficient because an instruction that generates one fused μop can go into any of the three decoders while an instruction that generates two μops can go only to decoder D0. I know that…
Gilgamesz
  • 4,727
  • 3
  • 28
  • 63
0
votes
4 answers

What is most effective and fastest way to remove string from beginning? (PHP micro-optimisation)

I have a string like www.host.com and I need to remove beginning from it (in this case www.) to make it just host.com. There is array of these beginnings (like: m., wap. and so on). How to do it in effective and fast way? Currently I am using this…
WebDevHere
  • 119
  • 1
  • 7
0
votes
0 answers

how to improve variance calculation performance using integral image in opencv

I'm writing c++ image processing project using opencv. i'm calculating variance of image for each pixel. You may say variance filter. For each pixel i calculate variance around that pixel with filter size. FilterSize much smaller then image…
fyo
  • 77
  • 2
  • 13
0
votes
1 answer

Pointer vs Value arguments and receivers trade-offs

I've come from C++ world with such things like the move semantic and RVO. Since that, I wonder are there any trade-offs when you pass arguments by value? In my case, I have pretty big structs that I need to pass to a bunch of functions. As I have…
Dení
  • 183
  • 1
  • 9