4 ms·
Chatgpt4 can do source to source optimization which is pretty cool. I got it to beat gcc at -03 on simple small toy problems. and it can do similar things wit
by naveen99 3y ago
Chatgpt4 can do source to source optimization which is pretty cool. I got it to beat gcc at -03 on simple small toy problems. and it can do similar things with python also. But it threw its hands up when I gave it a longer piece of code to optimize.
- alex_lav 3y agoAt my company we have some "loadbearing" code that was written by a mad scientist that no longer works at our company. We have a total ban on AI for source code analysis (so chatgpt, copilot etc are all banned). I've really wanted to throw some of the grosser parts of that codebase into gpt-4 just to see if it could bring some small amount of sanity.
- reidjs 3y agoDo you know why that policy is in place? Is it fear that the llm provider will steal company trade knowledge?
- esrauch 3y agoIt's probably both that is leaking your source out and the risk of it being a copyright violation if it spits out some GPL source verbatim and you check it in.
- Filligree 3y ago> if it spits out some GPL source verbatim Does that ever actually happen? I've only heard of it happening to people who forced the AI's hand by including the comments for said code in the prompt.
- callalex 3y agoWhile many software companies get away with an “it’ll be fine” attitude, that is not sufficient for all companies and industries. Sometimes things have to be provably correct.
- pclmulqdq 3y agoThis happens a lot, and you can easily walk into constructing such a prompt without knowing.
- minhazm 3y agoThere's a setting "Suggestions matching public code" that can be set to "Block" that I think is sufficient for most people's usage. But many companies don't want to involve themselves in any sort of liability.
- alex_lav 3y agoI work in a research facility, so the biggest fear is that our super top secret elite info will leak. The reality is it'd be used to refactor a lot of terrible code.
- dwattttt 3y agoIt does make sense that ChatGPT can beat gcc (or any compiler really); the compiler is forced to optimise code so that it still appears to work as if it's the source you wrote. Most importantly, if there are observable side-effects, compilers must preserve them, even though you know you don't actually care about them. An AI is not bound to preserve those, and can semantically change what you wrote, so long as the one semantic you wanted preserved is still there.
- esrauch 3y agoIt seems like compilers should have an interactive mode where it suggests code that is very similar but not technically perfectly the same that is more efficient and the can accept or decline the alternate version.
- oldmanhorton 3y agoThis sounds like an extension of performance lint rules which many languages/ecosystems already have.
- deleted 3y ago[deleted]
- insanitybit 3y agoA backend compiler is probably not in a good place to do that. Frontends could, however, and there are lots of tools already to make those suggestions for many languages. clippy in rust, for example, will tell you about removing needless allocations, etc, which a backend compiler might have a harder time doing.
- kmeisthax 3y agoThere's a Kaze Emanuar video where he tries to have ChatGPT-4 optimize parts of his already well-optimized Mario 64 ROM hack: https://www.youtube.com/watch?v=20s9hWDx0Io https://www.youtube.com/watch?v=20s9hWDx0Io
- naveen99 3y agoThe toy example for those curious: #include <stdio.h> int main(void) { int i; int a[2000] ; for(i = 0; i < 2000; i++){ a[i] = i ; } printf("%d\n", a[5]); } This program initializes an array `a` of size 2000, populates it with integers from 0 to 1999, and then prints the value at index 5, which is 5. Just as with the Python program, we can optimize this program significantly. Given that we're only interested in the sixth element (index 5) of the array, we don't need to construct and populate the entire array. Here's an optimized version of the code: #include <stdio.h> int main(void) { printf("%d\n", 5); }
- naveen99 3y agoBut when I tried to get it to remove the dependency on studio.h, it said that’s too hard. Might have gone further with a more reasonable request I guess. Also not necessary as gcc does that anyway.
- Izkata 3y agoCode indentation is 2 spaces on here, you have to do it to all the lines you want formatted that way. That's why the first one got a bunch of lines combined, it treated them as one paragraph instead of code.
- naveen99 3y agothanks. fixed.
- cypress66 3y agoPrintf is horribly slow compared to puts
- jmgao 3y agoputs isn't applicable here because you actually need to format the %d, but any compiler worth using (i.e. not MSVC: https://gcc.godbolt.org/z/zx74vY1za https://gcc.godbolt.org/z/zx74vY1za) will optimize a printf of a constant string ending in a newline into a puts.
- kaba0 3y agoI don’t think any of those examples would be materially different than finding a related problem on stackoverflow and applying the answer. LLMs are just good at searching and transforming between representations, but they really are not good at logical inferences.