Why is a CPU branch instruction slow?

A branch instruction is not inherently slower than any other instruction. However, the reason you heard that branches should avoided is because modern CPUs follow a pipeline architecture. This means that there are multiple sequential instructions being executed simultaneously. But the pipeline can only be fully utilised if it’s able to read the next instruction … Read more

How can I prevent GCC from optimizing out a busy wait loop?

I developed this answer after following a link from dmckee’s answer, but it takes a different approach than his/her answer. Function Attributes documentation from GCC mentions: noinline This function attribute prevents a function from being considered for inlining. If the function does not have side-effects, there are optimizations other than inlining that causes function calls … Read more

Why would introducing useless MOV store instructions speed up a tight loop in x86_64 assembly?

The most likely cause of the speed improvement is that: inserting a MOV shifts the subsequent instructions to different memory addresses one of those moved instructions was an important conditional branch that branch was being incorrectly predicted due to aliasing in the branch prediction table moving the branch eliminated the alias and allowed the branch … Read more

Examples where compiler-optimized functional code performs better than imperative code

There are cases where the same algorithm will optimize better in a pure context. Specifically, stream fusion allows an algorithm that consists of a sequence of loops that may be of widely varying form: maps, filters, folds, unfolds, to be composed into a single loop. The equivalent optimization in a conventional imperative setting, with mutable … Read more

How to find unused classes in my HTML?

This may be helpful: https://code.google.com/p/find-unused-classes/ . According to the description: It shows classes that exist in css selectors and do not exist on html page and like-verse. As Jim said, be warned that some classes may be unused by your stylesheets but still used in JavaScript.

tech