Posts

Showing posts from March 18, 2019

I optimized requestAnimationFrame calls by prebinding the animation function

Image
0 The normal flow is function animate() { requestAnimationFrame(animate); // do render stuff chicken.position.x++; } animate(); However when you encapsulate your code into a class Normal Animation Step in Class animate() { requestAnimationFrame(this.animate.bind(this)); // do render stuff this.chicken.position.x++; } // somewhere else this.animate.call(this); I noticed you can get a measurable execution speedup by prebinding the animate function to do this Optimized Animation Step animate() { requestAnimationFrame(this.animate_binded); // do render stuff this.chicken.position.x++; } // somewhere else this.animate_binded = this.animate.bind(this); this.animate(); I don't have heap analysis tools but I observed a measurable and repeatble drop i

Java Merge Sort on Linked List sorting only when smallest number is added first

Image
5 1 When I insert numbers in my linked list it only sorts everything when the first number added to it is the smallest. This is the unexpected behavior that I am getting: I insert the numbers in this order - 200, 25, 473, 23, 390 If I sort the list like that above and display it, I get this - 200, 390, 473 If I change 200 to 900 then sort the list, it only displays 900 It only works when I change 200 to the smallest number in the list like 1 (or anything less than 23), then it gives me the right output 1, 23, 25, 390, 473 For the linked list I insert the elements at the back of the the list, this is the code: public void insertAtBack(IntegerElement elem) { if (isFull()) { System.out.println("Unable to insert node into full list"); } else { Node temp = new Node(elem);