📜 ⬆️ ⬇️

Acceleration 3.7 times after removing Sleep () in WebKit

Geoff Garen of Apple found the Sleep () call in the TCMalloc function of the WebKit garbage collector's TCMalloc function.

-#if OS(WINDOWS) - Sleep(2); -#else - struct timespec tm; - tm.tv_sec = 0; - tm.tv_nsec = 2000001; - nanosleep(&tm, NULL); -#endif 

After removing Sleep, the performance of the collector in certain conditions increased by 3.7 times. This is a good example of how one small optimization can increase productivity several times.

On HN, there was a discussion about this: they say, why was there a call to Sleep () at all, if its use in back loops is considered a bad form. He was probably there for a certain reason, as indicated by a long comment in the code.

As a result, the developer who discovered the Sleep call in WebKit was discovered. He explained that initially this custom function for dynamic memory allocation TCMalloc was developed for servers, and this kind of spinlock was there for a certain reason, but this reason is probably not as relevant for WebKit as a browser engine.
')
Joff Garen himself spoke in the same sense, but in a more visual form :



The change in the WebKit code was made in May 2012, so the last Safari probably already works on an optimized version.

Source: https://habr.com/ru/post/150728/


All Articles