Only statically-link AdviceMap data that is used
- Dominant language
- Rust
- Stars
- 772
- Forks
- 352
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 93
Description
Currently, when the assembler is assembling a library or program, the `MastForestBuilder` is constructed with the set of statically-linked libraries, whose code (when referenced) will be copied into the final assembly. Additionally, to ensure that advice data provided (and used) by those libraries is present at runtime, it copies _all_ of the advice data of every statically-linked library into the final assembly.
That's a problem for assembled artifacts that need to be stored on-chain, as advice data can drastically inflate the size of the resulting binary. It is likely that the advice map data of a library may not be referenced at all by the parts of the library that are statically-linked, meaning that data is just wasting space.
I would suggest that we implement an analysis pass as part of the `Linker`, that determines what `AdviceMap` entries of statically-linked libraries are actually referenced by statically-linked procedures. This requires us to visit the MAST of those procedures and perform a kind of dataflow analysis, that looks for advice map instructions that take a key as argument and read data from the advice map, and reify the key passed as an argument.
In cases where the key cannot be statically computed (e.g. it is provided as an argument to a procedure, rather than referenced literally), we could handle them conservatively (i.e. mark all `AdviceMap` entries of the containing library as possibly-referenced). This would be safe, but possibly overly-conservative.
The initial task here is to take a look at how we would identify whether an advice map entry is used, in what cases we cannot do so, and then determine the feasibility and benefit of implementing the proposed analysis.
I also think we need to gather some data on how often advice map data is shipped with a library, how much data there is, and how likely it is that parts of a library that don't use that data are linked in to other artifacts _without_ the parts that do use the data.
Contributor guide
Assessment
This issue has not been assessed yet.