Skip to content

Perf: replace std::unordered_map with boost::unordered_flat_map/set#16849

Open
sbillig wants to merge 3 commits into
argotorg:developfrom
sbillig:flat-map
Open

Perf: replace std::unordered_map with boost::unordered_flat_map/set#16849
sbillig wants to merge 3 commits into
argotorg:developfrom
sbillig:flat-map

Conversation

@sbillig

@sbillig sbillig commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Description

Replaces all uses of std::unordered_map/set with boost unordered_flat_map/set, and replaces std::unordered_multimap with boost::unordered_multimap. This provides a nice speedup on the purplebench suite locally (though results were noisy on my laptop so take this with a grain of salt). I'd appreciate a benchmark run on the dedicated machine.

The only real risk here is flat_map's reference (in)stability across inserts. I don't see any cases where this is currently a problem. There may be some instances where unordered_map is better than flat_map, eg where the value type is large, or in cases with a lot of updates. I ran the BalancerV3Vault benchmark case, flat_map vs unordered_map for these instances locally and flat_map was never worse, but this could use more testing:

(these are cases where the value is non-trivial (eg std::set), and/or there's potentially a lot of mutation)
CommonSubexpressionEliminator.h:172
ControlFlowSideEffectsCollector.h:130
CommonSubexpressionEliminator.h:66
DataFlowAnalyzer.h:184
SSACFGBuilder.h:159

I'm sure using flat_map in more places was on everyone's radar; thought it was worthwhile running this experiment. Happy to roll back individual uses or whatever.

contract no via-IR via-IR
WETH9 -2.69% -6.95%
ChainlinkLINKLinkToken -4.73% -3.71%
MakerDAODSSJug -4.53% -4.98%
MakerDAODSSPot -4.50% -4.37%
ENSRegistryWithFallback -0.76% -4.15%
CompoundIIICometRewards -2.90% -3.57%
MakerDAODai -4.55% -5.31%
WrappedBitcoinWBTC -3.25% -4.64%
UniswapV4V4Quoter -3.56% -3.26%
TetherToken -3.42% -3.62%
LidoWstETH -5.30% -2.93%
ENSETHRegistrarController -4.29% -3.05%
MakerDAODSSVat -4.82% -7.90%
AaveV3VariableDebtTokenInstance -2.93% -4.29%
UniswapPermit2 -5.00% -3.87%
OETH -4.29% -2.89%
BoredApeYachtClub -3.16% -2.18%
AaveV3ATokenInstance -2.63% -3.90%
RocketDepositPool -4.27% -2.69%
Poap -3.89% -3.92%
FraxFinanceFRAXStablecoin -3.38% -5.27%
EigenLayerEigenPodManager -0.26% -3.48%
SafeGnosisSafe -4.46% -3.79%
CoWProtocolGPv2Settlement -4.25% -4.10%
EigenLayerStrategyManager -2.29% -2.47%
FiatTokenV2_2 -6.71% -4.66%
LidoAccountingOracle -6.59% -2.86%
UniswapV2UniswapV2Router02 -4.95% -3.30%
Morpho -6.42% -3.36%
SparkProtocolPool -3.13% -2.20%
AccessControlledOCR2Aggregator -7.40% -4.37%
PoolManager -2.22% -4.79%
UniswapV4PositionManager -1.07% -3.82%
CompoundIIICometWithExtendedAssetList -2.86% -1.30%
EulerSwap -3.30% -3.58%
UniswapV3SwapRouter02 -4.28% -1.99%
AaveV3PoolConfiguratorInstance -8.55% -3.48%
EtherfiLiquidityPool -4.12% -3.53%
AaveV3PoolInstance -1.23% -5.45%
ENSNameWrapper -6.82% -4.21%
UniswapV3NonfungiblePositionManager -4.19% -4.55%
AaveV4HubInstance -6.78% -2.82%
LidoWithdrawalQueueERC721 -6.57% -1.39%
UniswapV3Pool -2.65% -1.08%
BalancerV2Vault -3.38% -2.16%
BalancerV3Router -3.48% -0.85%
BalancerV3Vault -6.15% -2.46%
Total -3.88% -3.29%

Checklist

AI Disclosure

This is just a find-and-replace PR, and AI did it. AI also ran benchmarks for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant