With us is better!
Optimizing video codec for performance

I'm not a fan of optimizing something in advance. As a rule, at the development of programs, I don't ponder on performance at all, focusing only on algorithms. That was also in this case, before the moment, until I noticed that my computer does not have time to transcode video thread in real time. I did not divide transcoding process into several threads – it is just not needed, because any way I planned to broadcast several channels. Therefore, it would be more correct to carry out transcoding each of them in their own thread, and it doesn’t make sense to divide transcoding process of a single TV channel into several threads. Now it is time to do performance optimizing.

So, by using profiler, I have examined bottlenecks. Generally speaking, they coincided with expected - it was a module of movement compensation. Having analysed mathematical part of the module, I have not found any errors. Also nothing came into my mind about how to make it easier. Then I took extreme measures - I decided to examine assembly code of the most resource-intensive part of this module and try to optimize it. What was my surprise when I saw that the assembly code of function, which consumed 95% of the module resources, consisted of only two assembler directives, and such load was obtained by a huge number of function requests. But it can't be so, I did realize perfectly well logic of the motion compensation algorithm, and it does not match with what analyser and assembler were showing. As it is known, there are no miracles (though....), and with even greater zeal I began to check the logic of the module’s work on accordance of the chosen algorithm. This bore the results - it turned out that I worked out algorithm not so thoroughly. Thus, I put in it a number of calculations, which were unnecessary, and which were consumed enormous resources at the same time. It was enough to eliminate the problem - and all were put in right places, module's productivity increased by about 100%.

All this confirmed my point of view completely. Nowadays compilers cope with code optimization much better than a human, that is why meddling in assembly directives and optimize something in them just makes no sense. We should pay main attention to usable algorithms of calculations, while substitution of one algorithm to another, or its modernization can lead to greater productivity gain, than attempts of meaningless copying of C++ code on assembler.

Igor, October 2012.

Users' Comments Optimizing video codec for performance (1)
Hide comments
Posted by Guest, on 15-10-2016 19:23,
» Reply to this comment...

Add your comment