Skip to content

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:

ProjectChangeFiles compiled (with / without, after initial compile)Time to compile (with / without, after initial compile)
uniswap v4-coreadd Lock.lock(); at PoolManager.sol#L1071 / 192.25s / 165.13s
spark-psmchange amountOut < minAmountOut at PSM3.sol#L1253 / 282.14s / 16.15s
morpho-blue-bundlerschange if (assets < 0) at MorphoBundler.sol#L10611 / 3616.39s / 251.05s
morpho-blueadd require(assets != 0, ErrorsLib.ZERO_ASSETS) at Morpho.sol#L4241 / 231.01s / 133.73s
sablier lockupchange if (cliffTime < 0) at SablierLockup.sol#L4801 / 104781ms / 71.29s
soladyadd additional _setOwner(newOwner) at Ownable.sol#L1829 / 146.17s / 6.34s
euler evcchange SET_MAX_ELEMENTS to 11 at Set.sol#L728 / 309.17s / 9.40s