Since we don’t have AI yet we can only speculate to this answer. Now if you mean ML, that is a very different thing as machine learning is simple feature recognition of some given input data. It can be pretty damn good at what it does, and you can even hook a few different ML data structures together with something like a Monte Carlo algorithm to play things like chess, go, or shogi. This makes it very good at playing those games and we even found that not letting it learn from humans but instead simply by playing itself turns out to produce even better output (AlphaZero), but this is still ML. When it can watch humans play a game and learn the rules or read the rules and play the game by itself, we are probably getting near what we would call a special AI. When it can then apply what it learns from one game to another, or to dealing with a human, or how to pick a good stock, and mix everything it learns into applying it with everything else (like a human brain can) then we will have general AI.
My own research in the field is using computational biology to create an artificial brain using artificial neurons. Not the simple models used in most ML but fully spiking models where current is applied to soma of each neuron as a form of input which applies current through the synapses to connected neurons if it spikes. In this manner, myself and my colleagues that are doing the same research, are trying to build a computational model of a human brain, not a model of simple neuron connectivity. In this case we would have a human capable brain running in a computer. It should be capable of human level thought and since the computer can run much faster than of chemical-based synapses, it should eventually be much faster. Not only can it be much faster but it can be much larger and therefor capable of “remembering” much more than we can, and in fact, would have a photographic memory or even use the Internet like memory. Here’s some projects that are attempting this:
Now suppose we have a brain that is 1,000x (or 10,000x or 100,000x) the size of ours that never forgets anything. Imagine that you read every article in Wikipedia and could recall all of it including the biographic reference entries that you read as well to support the article. Suppose you read every scientific paper ever written and could recall them all exactly. How smart would you be? Super smart. And, contrary to common belief, the computer brain, like our own, would have creativity. Unless you believe in vitalism (and can accept there is no evidence for it) then there is no reason to believe that creativity is something special contained in a soul, so there is no reason that a computer simulation of a brain can’t be creative. This means it could write code.
Now suppose you were that brain that was super smart, read and recalled everything in Github, Sourceforge, every other code repo, the code to the operating system you were running on, the complete hardware specifications of the system you were running on, and even the code for yourself? Imagine with all that smartness you reprogram yourself to be even faster and have even more capabilities?
Do you think a hand-made computer program written by an inferior thinker with less than .001% of your knowledge could be better?
I guess we shall see.