- cross-posted to:
- tech@partizle.com
In the existing implementation in the C++ library, the code does a series of tests to see how many items it needs to sort and calls the dedicated sorting function for that number of items. The revised code does something much weirder. It tests if there are two items and calls out to a separate function to sort them if needed. If it’s greater than two items, the code calls out to sort the first three items. If there are three items, it returns the results of that sort.
If there are four items to sort, however, it runs specialized code that is extremely efficient at inserting a fourth item into the appropriate place within a set of three sorted items. This sounds like a weird approach, but it consistently outperformed the existing code.
Hopefully they can apply AI to the other challenging problems in programming like cache invalidation and naming things! 😆
ChatGPT is actually decently good at naming decompiled variables… cache invalidation… Is very hard