Thanks to everyone who participated in our
programming contest ! We summed it up and awarded the winners.
The challenge was to improve the
implementation of a doubly linked list of Node.js sources. This code is fast and efficient, but it was written for a specific application - storing lists of inactive timers. Therefore, the idleNext and idlePrev fields are added directly to the stored objects. The participants in the competition were tasked with making the code universal (so that one element could belong to several independent lists at the same time) without loss of performance.
The obvious solution is to add intermediate objects — list links — that contain the fields next, prev, and value. But this approach has a serious drawback: if we have only a link to the stored object, and it needs to be removed from the list, then we will have to sort through the entire chain. There is a loss of performance.
')
We appreciated those solutions, where instead of idleNext and idlePrev, a couple of fields are used with different names that are different in different lists. However, when accessing members of objects using the “square brackets” operator instead of “point”, the V8 compiler cannot perform important optimizations, so the code is slower.
Prizes were received by those participants who used the self-modifying code. If we replace idleNext and idlePrev in the list implementation with other names, and then force the interpreter to execute the resulting code (using the dot operator), the performance does not drop.
Details on how and for what we awarded points to participants, as well as all the decisions that we received - in the
repository on GitHub . Congratulations to the winners!
- Sergey Shpak - prize 1500 USD
- Ori Shalev - prize 1000 USD
- Alexander Lyakshev - prize 500 USD
Separately, we decided to mark the youngest participants - one of them is 12, and the other is 15 years old. Their team ranked seventh. Dmitry and Ruslan received a special prize - 350 USD.
Already thinking about the challenge for the next contest.