evolution need not necessarily be an improvement, foe example mammals have a blind spot in their eyes because of the optic nerve, octopuses don't have a blind spot. but octopuses were before mammals
I concur, I would say evolution is more like "adaption" than improvement.
Biological evolution has indeed lead much more frequently to simplified, streamlined structures good for a single purpose, which had evolved from more complex and more versatile structures, than to more complex structures that had evolved from simple structures.
The latter kind of evolution events, while very rare, had a greater importance by being the origin of various kinds of very successful living beings.
Your example shows that because evolution proceeds through random search through the space of solutions, inside the neighborhoods of the starting point, followed by the choice of the best solution among the candidates, it frequently fails to find a global optimum, but it remains stuck on a local optimum.
However, octopuses were not before mammals. Both octopuses and mammals had appeared around the middle of the Mesozoic, but this is not really relevant for their eyes, which already existed in much older ancestors, hundreds of millions of years earlier.
Cephalopods and vertebrates with complex eyes already existed during the Ordovician. Chordates with complex eyes might have already existed quite early during the Cambrian, most likely before the separation between cephalopods and other mollusks, at a time when mollusks must have had only simple eyes that could detect light and perhaps the shape of shadows, but which could not form images.
When cephalopods separated from the other mollusks, they did this by evolving the ability to swim, instead of being forced to crawl on the bottom like most mollusks. (Swimming was achieved by filling their shell with a gas, which made it buoyant, while the other mollusks were held on the bottom by the weight of the shell.)
Chordates have also separated from their ancestors by evolving the ability to be fast swimmers (the elastic and incompressible dorsal chord reduced the energetic cost of anguilliform swimming in comparison with that for worm-like bodies that need to contract a muscular layer in order to prevent the shortening of the body when it is flexed).
This is likely to not be a coincidence, so the evolution of complex eyes in chordates and cephalopods is likely to be linked with the evolution of swimming in both groups, which made important the detection of objects located in various directions, while for a bottom crawler it could have been sufficient to sense when a shadow appeared due to something coming above it.