by Paul-Craft · 3y ago · 0 comments
When it's not done by "artificial intelligence," we just call this "mutation testing": https://en.wikipedia.org/wiki/Mutation_testing
> The above algorithm shows what the new and improved libcxx is doing. It's basically quicksort except it switches to the sorting kernels and insertion sort when recursing into smaller slices.
This is a pretty standard technique, isn't it? You can eliminate hella recursive calls just by cutting off the bottom level of the call tree. For instance, take the following (Emacs lisp) functions:
(defun fib1 (n)
(if (or (= n 1) (= n 0))
1
(+ (fib1 (- n 1)) (fib1 (- n 2)))))
(defun fib2 (n)
(if (or (= n 1) (= n 0))
1
(if (= n 2)
2
(+ (fib2 (- n 1)) (fib2 (- n 2))))))
Using the first function to calculate (fib 5) makes 29 recursive calls before finally terminating, while the second only 17.With libcxx I think they even took the added step of schlepping in heapsort, which is kind of slow, but prevents adversaries from smashing your stack.
How does heapsort protect against a stack attack?
The bit I meant to comment on was the "kind of slow" part. It is true that heapsort tends to be slower than a well-implemented quicksort, but you don't use heapsort when you need the absolute best speed. The (IMO) best thing about heapsort is that its best case and worst case are the same order of magnitude, so sorting n things will take a fairly consistent amount of time, no matter what.