4 ms·
Are there tools to evaluate (imperfectly) the percent of a binary that actually gets used? Like, run an application, run the watcher tool, then “walk the appli
by Waterluvian 4y ago
Are there tools to evaluate (imperfectly) the percent of a binary that actually gets used?
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.
- bkallus 4y agoI don't know, but one could implement this without too much difficulty as a wrapper around afl-showmap.
- xcambar 4y agoNo, because you can't prove every piece of functionality has been executed.
- Waterluvian 4y agoTrue. What’s what I meant by (imperfectly). But perfect can’t be the enemy of good. There’s tremendous value in the data. You wouldn’t use it to just omit those bits. But it tells you a lot.
- ergvgdvgrd 4y agoRun time "code coverage" would give you that.
- speps 4y agoRead this classic article: https://fgiesen.wordpress.com/2012/04/08/metaprogramming-for-madmen/ https://fgiesen.wordpress.com/2012/04/08/metaprogramming-for... The section called "A plan so insane, it might just work" describes what you mention.
- tscherno 4y agoIn an interview I can't find anymore a developer from Farbrausch said that they used such a method to optimize the .kkrieger demo and ended up having a bug in the main menu because while recording the coverage the user never scrolled to a certain main menu item. So once you scrolled there you couldn't scroll up anymore.
- Waterluvian 4y agoThis reminds me of Naughty Dog overwriting standard library functions to gain more RAM for Crash Bandicoot. They would just “delete a function and see if the game still worked.”
- speps 4y agoSee my comment in the same parent: https://news.ycombinator.com/item?id=33575452 https://news.ycombinator.com/item?id=33575452
- 323 4y agoExecutable binaries are memory mapped into memory. So the pages are lazily loaded. So in theory you could study how many of the pages (4 KB each) of the binary were actually loaded to get a rough idea. Obviously not very precise since it has a 4 KB granularity.
- bitwize 4y agoYou can run a profiler to determine which functions actually get called. 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.
- heavyset_go 4y agoThat feels halting problem-esque.
- Epa095 4y agoIt definitely is if you want a 100% correct and 100% certain answer. But if you accept 3 categories 1: this we know is used 2: this we know is not used, 3 this we don't know anything about, then it's doable.
- colejohnson66 4y agoBut (2) requires knowing everything the binary will do. You can’t know what something won’t do without knowing what it will do.
- tadfisher 4y agoYou can do (2) if you can tolerate false positives. For example, if a symbol isn't referenced literally elsewhere in the binary, consider it unused, but add a configuration option to keep it in case it is referenced dynamically. The JVM world has been doing this for years with ProGuard.
- yarg 4y agoBranches are a problem, depending on the number of parameters needed to be evaluated: > Solving a constraint satisfaction problem on a finite domain is an NP-complete problem in general. https://en.wikipedia.org/wiki/Complexity_of_constraint_satisfaction https://en.wikipedia.org/wiki/Complexity_of_constraint_satis...