3 ms·
Could it be possible to do "profile guided tree-shaking" to build a small module with all the code that's necessary for the application and pull-in less used fu
by screcth 2y ago
Could it be possible to do "profile guided tree-shaking" to build a small module with all the code that's necessary for the application and pull-in less used functionality on-demand using dynamic linking?
If tree-shaking was done based on production information it may be possible to prune a lot of dead/almost-dead code without having to implement sophisticated static analysis algorithms.
- kevindamm 2y agoThere is a substantial risk there unless you can hit all the edge cases and error conditions when profiling. Even a good fuzzer can miss a very rare state. Then when you hit it in real use there's no code to handle it! Profile-based optimization and JITting is plausible because the corner cases are still there, just not optimized.
- screcth 2y agoI completely agree, that's why in that case you could download the missing code from the server and load it using dynamic linking. The server would then mark it as reachable so it's delivered as part of the main bundle next time. I would expect the bundle to converge quickly to the set of functions that are actually reachable. Aditionally, it's very likely that the sets of reachable code of two versions of the same app have significant overlap, so the information collected for version N could be used as a starting point for N+1, and so on.
- avodonosov 2y ago"less used functionality on-demand" - so the code to handle the rare case remains available, on demand.
- nurple 2y agoA lazy chunked delivery strategy like used in the k8s stargz-snapshotter[0] project could be effective here, where it only pulls chunks as needed, but it would probably require wasm platform changes. [0] https://github.com/containerd/stargz-snapshotter https://github.com/containerd/stargz-snapshotter
- avodonosov 2y agoI experimented with that for javascript: https://github.com/avodonosov/pocl https://github.com/avodonosov/pocl