One of my many "eventually maybe" project ideas - although I'm hoping other optimizations at other levels of the tech stack will make it mostly unnecessary - is an optimizing compiler turning shell scripts into single binaries with inlined implementations of all the shell commands it knows about.
That way for example canonical source code can look like `curl ... | sed 's/foo/bar/'` and the binary might use something like libcurl (ideally in a static includes way, although I suspect the world will keep insisting on the less efficient-to-implement approach of link-time optimization) and an inlined implementation of just the string-replacing logic of sed.
The unfortunate thing is that a realistic implementation would need a dictionary of heuristics and definitions - for a program with this name, parse the arguments like so, and based on that pick a pre-written implementation of it, and inline it. So if you have a non-standard or uncommon program, or are using a program in a very unusual or unexpected way, you might need to add/enhance/override the detection heuristics or program definition.
It would also probably never have full coverage over weird behavior edge cases. For example, if you are deliberately doing something weird like sending a SIGSTOP to one process in your shell script while another process piping into it is still running, then you can't optimize that pipeline into one process, at least not in the general case. (On Linux you can signal a specific thread instead of process, but then the sender has to be adjusted too.)











