Dynamic Test Linking
v1.1 release comes with dynamic test linking feature, built on top of Solar, which eliminates redundant test compilation when changing the contract logic, Foundry skips recompiling large test suites, resulting in massive time savings.
How it works:
On the initial build, Foundry preprocesses test contracts by extracting constructor parameters of the contracts under test and replacing direct instantiations with deployCode
cheatcodes.
Subsequent compilations reuse pre-built artifacts for deployed contracts instead of recompiling both the source and all associated test contracts. Dynamic test linking capability is built on top of Solar, the blazingly fast and modular Solidity compiler.
You can enable this feature by setting the dynamic_test_linking
configuration option to true
in your foundry.toml
file:
[profile.default]
...
dynamic_test_linking = true
OR by passing the --dynamic-test-linking
flag to the forge build
command:
forge build --dynamic-test-linking
We are looking into enabling this by default in the future.
Benchmarks from the PR show greater than 10x speedup in compilation time for large projects:
Project | Change | Files compiled (with / without, after initial compile) | Time to compile (with / without, after initial compile) |
---|---|---|---|
uniswap v4-core | add Lock.lock(); at PoolManager.sol#L107 | 1 / 19 | 2.25s / 165.13s |
spark-psm | change amountOut < minAmountOut at PSM3.sol#L125 | 3 / 28 | 2.14s / 16.15s |
morpho-blue-bundlers | change if (assets < 0) at MorphoBundler.sol#L106 | 11 / 36 | 16.39s / 251.05s |
morpho-blue | add require(assets != 0, ErrorsLib.ZERO_ASSETS) at Morpho.sol#L424 | 1 / 23 | 1.01s / 133.73s |
sablier lockup | change if (cliffTime < 0) at SablierLockup.sol#L480 | 1 / 104 | 781ms / 71.29s |
solady | add additional _setOwner(newOwner) at Ownable.sol#L182 | 9 / 14 | 6.17s / 6.34s |
euler evc | change SET_MAX_ELEMENTS to 11 at Set.sol#L7 | 28 / 30 | 9.17s / 9.40s |