Skip to content

Dynamic Test Linking

dynamic_test_linking is a configuration that speeds up project compilation (after first compile) by compiling only changed sources in the src/ directory and linking the test bytecode dynamically, hence avoid compilation of the solidify files in the test/ directory.

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