The section called "A plan so insane, it might just work" describes what you mention.
I'm reminded of a Smalltalk hack called Spoon. It required two systems: a host system running the full Smalltalk with all its classes, and a target system which had the barest possible Smalltalk environment. Any time an attempt was made to access a class that didn't exist on the target system, it would ask the host system for that class and if available, download it in serialized bytecode form and run it. This may have worked at method level granularity -- i.e., classes were only populated with methods that were actually used on the target system -- I'm not sure. But the result was the target system only contained enough of Smalltalk to actually run the program.
> Solving a constraint satisfaction problem on a finite domain is an NP-complete problem in general.
https://en.wikipedia.org/wiki/Complexity_of_constraint_satis...
Like, run an application, run the watcher tool, then “walk the application” as best as possible and get an output: “35% of the binary was never read.” ?
What’s on my mind is evaluating the actual result of tools and methods for not including unnecessary things. I struggle with this in web land. Tree shaking and such does a wonderful job but I honestly don’t know how much of my bundle is still superfluous.