28

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.

top 5 comments
sorted by: hot top controversial new old
[-] troye888@lemmy.one 4 points 1 year ago

I wonder if we will soon be able to apply these techniques to general compiler optimizations, would love to see which crazy optimizations we are leaving on the table there.

[-] Hexorg@beehaw.org 3 points 1 year ago

I work quite close to these topics and the computational complexity of compiler optimization is harder than sorting algorithms. And while I’ve seen ML develop heuristics for combinatorial logic, pushdown automata and Turning machines are still too complex. Though we’re approaching pushdown automata already. I think ML driven compiler optimizations are at least 10 years away. Likely more.

[-] cavemeat@beehaw.org 2 points 1 year ago

Ah you beat me to it, this is really cool news :D

[-] schizanon@beehaw.org 1 points 1 year ago

Hopefully they can apply AI to the other challenging problems in programming like cache invalidation and naming things! 😆

[-] Hexorg@beehaw.org 1 points 1 year ago

ChatGPT is actually decently good at naming decompiled variables… cache invalidation… Is very hard

this post was submitted on 08 Jun 2023
28 points (100.0% liked)

Programming

13372 readers
1 users here now

All things programming and coding related. Subcommunity of Technology.


This community's icon was made by Aaron Schneider, under the CC-BY-NC-SA 4.0 license.

founded 1 year ago
MODERATORS