diff options
author | chriseth <chris@ethereum.org> | 2018-05-09 16:56:48 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-05-09 16:56:48 +0800 |
commit | c79351efb05be08f3f1797c8cf6ff50988b74763 (patch) | |
tree | 0ee137fa5a96b7b7b05ac5702dc8a386980f8fd6 /libevmasm/PathGasMeter.cpp | |
parent | 58c63dcc9ce61b2742a10dc337cc5d0fd8739471 (diff) | |
parent | bbae4fb0ef41361d24eadcc0a93cf02052493d10 (diff) | |
download | dexon-solidity-c79351efb05be08f3f1797c8cf6ff50988b74763.tar dexon-solidity-c79351efb05be08f3f1797c8cf6ff50988b74763.tar.gz dexon-solidity-c79351efb05be08f3f1797c8cf6ff50988b74763.tar.bz2 dexon-solidity-c79351efb05be08f3f1797c8cf6ff50988b74763.tar.lz dexon-solidity-c79351efb05be08f3f1797c8cf6ff50988b74763.tar.xz dexon-solidity-c79351efb05be08f3f1797c8cf6ff50988b74763.tar.zst dexon-solidity-c79351efb05be08f3f1797c8cf6ff50988b74763.zip |
Merge pull request #4068 from ethereum/gasEstimatorPerformance
Gas estimator performance
Diffstat (limited to 'libevmasm/PathGasMeter.cpp')
-rw-r--r-- | libevmasm/PathGasMeter.cpp | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/libevmasm/PathGasMeter.cpp b/libevmasm/PathGasMeter.cpp index 3fe682b7..cdadba76 100644 --- a/libevmasm/PathGasMeter.cpp +++ b/libevmasm/PathGasMeter.cpp @@ -43,7 +43,7 @@ GasMeter::GasConsumption PathGasMeter::estimateMax( auto path = unique_ptr<GasPath>(new GasPath()); path->index = _startIndex; path->state = _state->copy(); - m_queue.push_back(move(path)); + queue(move(path)); GasMeter::GasConsumption gas; while (!m_queue.empty() && !gas.isInfinite) @@ -51,12 +51,23 @@ GasMeter::GasConsumption PathGasMeter::estimateMax( return gas; } +void PathGasMeter::queue(std::unique_ptr<GasPath>&& _newPath) +{ + if ( + m_highestGasUsagePerJumpdest.count(_newPath->index) && + _newPath->gas < m_highestGasUsagePerJumpdest.at(_newPath->index) + ) + return; + m_highestGasUsagePerJumpdest[_newPath->index] = _newPath->gas; + m_queue[_newPath->index] = move(_newPath); +} + GasMeter::GasConsumption PathGasMeter::handleQueueItem() { assertThrow(!m_queue.empty(), OptimizerException, ""); - unique_ptr<GasPath> path = move(m_queue.back()); - m_queue.pop_back(); + unique_ptr<GasPath> path = move(m_queue.rbegin()->second); + m_queue.erase(--m_queue.end()); shared_ptr<KnownState> state = path->state; GasMeter meter(state, m_evmVersion, path->largestMemoryAccess); @@ -117,7 +128,7 @@ GasMeter::GasConsumption PathGasMeter::handleQueueItem() newPath->largestMemoryAccess = meter.largestMemoryAccess(); newPath->state = state->copy(); newPath->visitedJumpdests = path->visitedJumpdests; - m_queue.push_back(move(newPath)); + queue(move(newPath)); } if (branchStops) |