mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
[yul-phaser] ProgramCache::calculateTotalCachedCodeSize(): Replace default weights with ones that better correlate with memory usage
This commit is contained in:
parent
bff012c76d
commit
1fa689e951
@ -214,11 +214,11 @@ BOOST_FIXTURE_TEST_CASE(startRound_should_remove_entries_older_than_two_rounds,
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(gatherStats_should_return_cache_statistics, ProgramCacheFixture)
|
||||
{
|
||||
size_t sizeI = optimisedProgram(m_program, "I").codeSize(CodeWeights{});
|
||||
size_t sizeIu = optimisedProgram(m_program, "Iu").codeSize(CodeWeights{});
|
||||
size_t sizeIuO = optimisedProgram(m_program, "IuO").codeSize(CodeWeights{});
|
||||
size_t sizeL = optimisedProgram(m_program, "L").codeSize(CodeWeights{});
|
||||
size_t sizeLT = optimisedProgram(m_program, "LT").codeSize(CodeWeights{});
|
||||
size_t sizeI = optimisedProgram(m_program, "I").codeSize(CacheStats::StorageWeights);
|
||||
size_t sizeIu = optimisedProgram(m_program, "Iu").codeSize(CacheStats::StorageWeights);
|
||||
size_t sizeIuO = optimisedProgram(m_program, "IuO").codeSize(CacheStats::StorageWeights);
|
||||
size_t sizeL = optimisedProgram(m_program, "L").codeSize(CacheStats::StorageWeights);
|
||||
size_t sizeLT = optimisedProgram(m_program, "LT").codeSize(CacheStats::StorageWeights);
|
||||
|
||||
m_programCache.optimiseProgram("L");
|
||||
m_programCache.optimiseProgram("Iu");
|
||||
|
@ -135,7 +135,7 @@ size_t ProgramCache::calculateTotalCachedCodeSize() const
|
||||
{
|
||||
size_t size = 0;
|
||||
for (auto const& pair: m_entries)
|
||||
size += pair.second.program.codeSize(CodeWeights{});
|
||||
size += pair.second.program.codeSize(CacheStats::StorageWeights);
|
||||
|
||||
return size;
|
||||
}
|
||||
|
@ -19,6 +19,8 @@
|
||||
|
||||
#include <tools/yulPhaser/Program.h>
|
||||
|
||||
#include <libyul/optimiser/Metrics.h>
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
@ -44,6 +46,29 @@ struct CacheEntry
|
||||
*/
|
||||
struct CacheStats
|
||||
{
|
||||
/// Weights used to compute totalCodeSize.
|
||||
/// The goal here is to get a result proportional to the amount of memory taken by the AST.
|
||||
/// Each statement/expression gets 1 just for existing. We add more if it contains any extra
|
||||
/// data that won't be visited separately by ASTWalker.
|
||||
static yul::CodeWeights constexpr StorageWeights = {
|
||||
/* expressionStatementCost = */ 1,
|
||||
/* assignmentCost = */ 1,
|
||||
/* variableDeclarationCost = */ 1,
|
||||
/* functionDefinitionCost = */ 1,
|
||||
/* ifCost = */ 1,
|
||||
/* switchCost = */ 1,
|
||||
/* caseCost = */ 1,
|
||||
/* forLoopCost = */ 1,
|
||||
/* breakCost = */ 1,
|
||||
/* continueCost = */ 1,
|
||||
/* leaveCost = */ 1,
|
||||
/* blockCost = */ 1,
|
||||
|
||||
/* functionCallCost = */ 1,
|
||||
/* identifierCost = */ 1,
|
||||
/* literalCost = */ 1,
|
||||
};
|
||||
|
||||
size_t hits;
|
||||
size_t misses;
|
||||
size_t totalCodeSize;
|
||||
|
Loading…
Reference in New Issue
Block a user